5

I have been having trouble getting some text to line up correctly and was hoping I could get some assistance with this. My code is below, as well as a screenshot of the output. I've highlighted the text to better show where the edges are.

\begin{flushleft}
``The time has come,'' the Walrus said,\\
``To talk of many things:\\
Of shoes, and ships, and ceiling wax,\\
Of cabbages and kings.\\
And why the sea is boiling hot,\\
And whether pigs have wings.''
\end{flushleft}

Alignment issue

This should all be left aligned, but instead lines 1, 3 & 4 are aligned to a certain point, lines 5 & 6 are aligned to a slightly different point, and line 2 is aligned to a slightly different point again. How can I fix this?

Edited to add: it appears the 'microtype' package is loaded in the template I am using. This may be the cause of this and other related problems.

9
  • 1
    You can use a tabular: \documentclass{article} \begin{document} \begin{tabular}{@{}l@{}} The time has come,'' the Walrus said,\\ To talk of many things:\\ Of shoes, and ships, and ceiling wax,\\ Of cabbages and kings.\\ And why the sea is boiling hot,\\ And whether pigs have wings.'' \end{tabular} \end{document}`. Is that an option?
    – user11232
    Commented Sep 22, 2015 at 5:33
  • 3
    The code you show would align the quotes on the first two lines at the same point using the standard definition of flushleft so if you are getting that output the problem is in code you have not shown. Please always provide a complete small document that demonstrates the problem so people can reproduce/debug. The O and the A look like natural variation in the font sidebearings but again impossible to tell without seeing the code. Commented Sep 22, 2015 at 6:42
  • I am still very new to LaTeX, so I'm not sure what code would be relevant. If it helps, this is the template I used. Could you perhaps instead suggest possible code that could interact with this sort of thing to produce a result like this? That would give me a start to help me track down the source of this bug.
    – Ulysses
    Commented Sep 22, 2015 at 6:54
  • @HarishKumar Thank you for your suggestion. I don't believe 'tabular' would be a suitable workaround as I am also seeing this issue when I centralise text - I get tiny little non-uniform offsets that mean things aren't quite perfectly centralised.
    – Ulysses
    Commented Sep 22, 2015 at 7:02
  • 1
    If you want to try to track down the bug on your own, you could follow some of the suggestions here
    – Thruston
    Commented Sep 22, 2015 at 10:53

2 Answers 2

9

The sticking into the left margin of the second line comes from the character protrusion feature. Very likely package microtype is loaded.

The protrusion of the first line is prevented by \begin{flushleft}, which adds an invisible empty box at the very beginning of the paragraph. This can be seen by \showlists with \showboxbreadth=\maxdimen\showboxdepth=\maxdimen. The start of the line:

\hbox(6.94444+1.94444)x345.0, glue set 87.81987fil
.\hbox(0.0+0.0)x0.0
..\glue 0.0
..\glue 0.0
..\glue -5.0
..\hbox(0.0+0.0)x0.0
..\glue 5.0
.\penalty 0
.\OT1/cmr/m/n/10 \ (ligature ``)
.\OT1/cmr/m/n/10 T
.\OT1/cmr/m/n/10 h
.\OT1/cmr/m/n/10 e

The protrusion works, when the penalty and the box are removed:

\documentclass{article}
\usepackage{microtype}

\begin{document}
\begin{flushleft}
\noindent
\unpenalty\begingroup\setbox0=\lastbox\endgroup
``The time has come,'' the Walrus said,\\
``To talk of many things:\\
Of shoes, and ships, and ceiling wax,\\
Of cabbages and kings.\\
And why the sea is boiling hot,\\
And whether pigs have wings.''
\end{flushleft}
\end{document}

Result

Or with changing the definition of flushleft:

\documentclass{article}
\usepackage{microtype}

\makeatletter
\g@addto@macro\flushleft{%
  \everypar=\expandafter{%
    \the\everypar
    \unpenalty
    \begingroup
      \setbox0=\lastbox
    \endgroup
  }%
}
\makeatother

\begin{document}
\begin{flushleft}
``The time has come,'' the Walrus said,\\
``To talk of many things:\\
Of shoes, and ships, and ceiling wax,\\
Of cabbages and kings.\\
And why the sea is boiling hot,\\
And whether pigs have wings.''
\end{flushleft}
\end{document}
3
  • The package 'microtype' does indeed appear to be loaded. Unfortunately I am not in a position to test your solution, as I am no longer using this template, but thank you anyway.
    – Ulysses
    Commented Oct 5, 2015 at 6:45
  • I'm a little confused as to what the microtype package actually does, and therefore whether it's useful or not. It seems the simplest solution to this problem would be to just not load this package. What sort of effect would this have on the rest of the document?
    – Ulysses
    Commented Oct 7, 2015 at 2:35
  • 1
    @Ulysses Protrusion feature, this should make the left and right edges of a text block appear more smooth. HZ algorithm: additional stretch and shrink capabilities of letters, this makes easier and better line breaks. Commented Oct 7, 2015 at 4:19
1

As pointed out by @DavidCarlisle in a comment, flushleft alone won't cause this and the the quotes on the first two lines should align at the same point. \raggedright, on the other hand, doesn't have that behavior and works fine in most situations.

You can simply do this (without microtype):

\documentclass{article}     
\begin{document}

{\raggedright%
``The time has come,'' the Walrus said,\\
``To talk of many things:\\
Of shoes, and ships, and ceiling wax,\\
Of cabbages and kings.\\
And why the sea is boiling hot,\\
And whether pigs have wings.''
}

\end{document}

enter image description here

Or this (with \usepackage{microtype}):

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .