5
$\begingroup$

The following looks wrong to me, how can I fix the alignment for the whole paragraph?

t = StringJoin @@ Table["abcd ", {60}];
Framed[Text[Style[t, TextAlignment -> Left]]]

enter image description here

Update

Thanks for the two answers. I'm still confused by the spacing and alignment of the first line here:

![enter image description here]

and (when resizing the notebook) the first line looks wrong:

enter image description here

Is there a better way to control this in Cell vs TextCell vs Text, and in a way that doesn't break when changing notebook window size or magnification?

$\endgroup$
3
  • $\begingroup$ You're Right example shows the space that is included since t ends with "... abcd ". If you do Framed @ TextCell[StringTrim @ t, TextAlignment->Right] the space will go away. $\endgroup$
    – Carl Woll
    Commented Jan 31, 2022 at 19:42
  • $\begingroup$ @CarlWoll Ah my mistake, I've updated the example $\endgroup$
    – user5601
    Commented Jan 31, 2022 at 19:47
  • 2
    $\begingroup$ This might be a bug in TextCell . You can work around it by adding a Row wrapper, e.g., Framed @ TextCell[Row[{Style[t, TextAlignment->Left, LineIndentMaxFraction->0]}]] If possible, try to control things using TextCell options. If you can't, you might need to add Row wrappers. $\endgroup$
    – Carl Woll
    Commented Jan 31, 2022 at 19:57

2 Answers 2

8
$\begingroup$

Use the option LineIndent:

enter image description here

Framed[Text[Style[t, TextAlignment -> Left, LineIndent -> 0]]]

enter image description here

or the option LineIndentMaxFraction:

Framed[Text[Style[t, TextAlignment -> Left, LineIndentMaxFraction -> 0]]]

enter image description here

$\endgroup$
2
  • $\begingroup$ If LineIndent -> n shifts the first line to the left, do you agree that LineIndent -> -n should shift only the first line to the right? $\endgroup$
    – user5601
    Commented Jan 31, 2022 at 18:27
  • $\begingroup$ I meant how can I indent the first line to the right? $\endgroup$
    – user5601
    Commented Jan 31, 2022 at 19:44
3
$\begingroup$

If you want to output something that looks like text, use TextCell:

Framed @ TextCell[t]

enter image description here

Another possibility:

TextCell[t, CellFrame->True]

(* Same picture *)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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