我一直无法让一些文本正确对齐,希望能得到一些帮助。我的代码如下,还有输出的屏幕截图。我突出显示了文本以更好地显示边缘的位置。
\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}
这些都应该左对齐,但实际上,第 1、3 和 4 行对齐到某个点,第 5 和 6 行对齐到略有不同的点,第 2 行再次对齐到略有不同的点。我该如何修复这个问题?
编辑后添加:看来我使用的模板中已加载了“microtype”包。这可能是导致此问题和其他相关问题的原因。
答案1
插入第二行左边距是由于字符突出的特征。很可能microtype
已加载包。
用 可防止第一行突出\begin{flushleft}
,这会在段落的最开始处添加一个不可见的空框。用 可看到\showlists
该\showboxbreadth=\maxdimen\showboxdepth=\maxdimen
框。行的开头:
\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
当点球点和禁区被移除时,突出部分就会起作用:
\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}
或者改变的定义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}
答案2
正如 @DavidCarlisle 在评论中指出的那样,flushleft
单独不会导致这种情况,并且前两行的引号应该在同一点对齐。\raggedright
另一方面,没有那种行为并且在大多数情况下工作正常。
您可以简单地执行此操作(无需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}
或者这样(带有\usepackage{microtype}
):