2
$\begingroup$

I am using the command:

Print["A paragraph goes in here; a subparagraph goes here; etc."]

The output text has line returns that differ from where they are in the input text. How can I make the output text look just like the input text? And with a more readable font than the mma default?

$\endgroup$
2
  • 2
    $\begingroup$ In general, Print is not the right command if you want to produce nicely formatted output. It's more for diagnostic purposes. Are you insisting on using Print? $\endgroup$
    – Jens
    Sep 14 '16 at 19:15
  • $\begingroup$ I am not insisting on using Print. What is the right command? $\endgroup$ Sep 14 '16 at 20:52
3
$\begingroup$

Print just displays the given text. Style allows to format the text in a variety of styles, e.g.

Style["A paragraph goes in here; \n a subparagraph goes here; \n etc.",
Blue, 24, Italic, FontFamily -> "Courier", LineSpacing -> {1, 0}]

enter image description here

A line break is introduced with \n, and the list of available fonts can be obtained with $FontFamilies. For an exhausting list of possibilities achievable, see the documentation for Style.

$\endgroup$
12
  • $\begingroup$ Thanks for your help. I applied your suggestion like so: $\endgroup$ Sep 14 '16 at 21:11
  • $\begingroup$ Style["Location classifications; \n 1 = Openings that users will \ touch frequently: buttons, usb jack, audio jack, charging ports, \ etc.; \n 2 = Openings or seams that users will touch infrequently: \ speaker holes, microphone openings, housing/mating seams, etc.; \n 3 \ = The screen; \n 4 = Surfaces: the back of the device, etc.", Black, \ 14, Plain, FontFamily -> "Arial", LineSpacing -> {1.5, 0}] $\endgroup$ Sep 14 '16 at 21:12
  • $\begingroup$ But the line still breaks unnecessarily between the words "touch" and "infrequently"??? $\endgroup$ Sep 14 '16 at 21:13
  • 2
    $\begingroup$ For future cases: (1) don't extend the scope of the initial question in the comments; edit the question accordingly or post a new one; (2) don't make prolonged discussions in the comments; (3) when posting MMA code in the comments, enclose it in the grave accents, `, that you can find in the upper left part of the keyboard. $\endgroup$
    – corey979
    Sep 14 '16 at 22:42
  • 1
    $\begingroup$ @Michael With the option setting LineBreakWithin -> False for Style there will be no extra line breaks, even if the with of the window is to small to display the lines completely. One can use Pane for more options (size, scrolling, scrollbars, magnification, ...). From you question it is not clear how the output should look like and how it's related to the TableHeadings in your answer. $\endgroup$
    – Karsten 7.
    Sep 15 '16 at 11:11
3
$\begingroup$

If you need strict control on the appearance of the output, you could consider using CellPrint which gives you maximum flexibility.

For example, you can print a cell with style "Text":

CellPrint@TextCell["A paragraph goes in here; a subparagraph goes here; etc.", "Text"]

You can print a cell with specific formatting:

CellPrint[TextCell[
  Row[{"The equation ", ExpressionCell[TraditionalForm[x^2 == -1]], " has 2 solutions."}],
   "Text"]]

I refer you to the Documentation pages for ExpressionCell, TextCell and CellPrint for additional examples.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.