我想将文本在两个单词后左对齐,如下图所示。我该如何解决这个问题?谢谢。
\documentclass[12pt]{report}
\usepackage[hidelinks]{hyperref}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[turkish,english,shorthands=:!]{babel}
\usepackage{apacite}
\usepackage[a4paper,left=30mm,top=30mm,right=25mm,bottom=25mm]{geometry}
\usepackage{epigraph}
\usepackage{graphicx}
\usepackage{float}
\usepackage{mathptmx}
\usepackage[titletoc,title]{appendix}
\usepackage{afterpage}
\usepackage[doublespacing]{setspace}
\usepackage{tocloft}
\usepackage{url}
\usepackage{indentfirst}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{longtable}
\usepackage{lipsum}
\begin{document}
\thispagestyle{plain}
\phantomsection
\begin{center}
Yüksek Lisans Tezi\\
\singlespacing %\doublespacing
\addcontentsline{toc}{chapter}{ÖZET}
{\fontsize{12pt}{12pt}\selectfont \textbf{\MakeUppercase{Özet}}}\\
\vspace{\baselineskip}
THESIS NAME\\
\singlespacing
Writer's Name\\
\singlespacing
Teknik Üniversitesi\\
Fen Bilimleri Enstitüsü\\
A Anabilim Dalı\\
Danışman: Dr. John DOE\\
2019, 100 (Tez Sayfa), 5 (Ek Sayfalar)
\end{center}
%%% Özet
\par Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\\
\singlespace
\noindent \textbf{Anahtar Kelimeler} :Ullamco Laboris Nisi, Aliquip, Commodo, Consequat, Duis, Aute, Irure Dolor Reprehenderit, Voluptate, Velit, Vsse, Cillum, Dolore Deu Fugiat, Nulla, Pariatur, Excepteur, Sint, Occaeca Cupidatat, Proident
\clearpage
\end{document}
答案1
这个答案在 2018 年可能没有什么意义,但无论如何......
Torbjørn T. 的回答非常好(我投了赞成票),但了解底层 TeX 引擎内部实际发生什么的 LaTeX 用户可能不禁会指出,这给排版引擎本身带来了不必要的负担。事实上,环境tabularx
通过重复排版每个“ -column”几次来工作X
,直到达到预期的结果;现在,在这种情况下,环境确实能够X
在第一次尝试中猜出唯一 -column 的正确宽度,只排版一次列本身(实验可以证明),因此 Torbjørn 的解决方案可以看作是 Fran 的自动化版本,不需要手动指示 的宽度\parbox
;事实上,即使不是这样,以今天(以及昨天……)计算机的速度,使用 造成的负担tabularx
无论如何都无关紧要;但熟悉底层 TeX 引擎的用户非常清楚,它包含一种专门用于实现这种效果的机制(称为悬挂缩进在排版世界中,段落算法是排版中最基本的程序之一,也是排版算法不可或缺的一部分。因此,利用这种机制的解决方案可能会引起人们的兴趣,至少从优雅的角度来看是如此。毕竟,如果TeXbook在第 208 页提醒我们,
美观比效率更重要,
应该如何评价那些结合了美学的东西和效率?
(请注意,本解决方案在行间粘连的管理方面也明显更胜一筹,这是我们不想在此讨论的话题;此外,它允许在缩进的段落中间进行分页,这可能是好事也可能是坏事,具体取决于具体情况。)
在下面的代码中,我们定义:
名为的命令
\mySingleParHangFrom
,可用于排版单段带有悬挂缩进;当此单段结束后将恢复正常边距;一个名为 的环境
myHangFrom
,如果您想要排版几个带有悬挂缩进的段落,则应该使用它;这种悬挂缩进将持续到环境结束。
代码:
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\makeatletter
\newcommand*\mySingleParHangFrom[1]{%
\par
\@hangfrom{\textbf{#1}\enspace}%
\ignorespaces
}
\newenvironment*{myHangFrom}[1]{%
\par
\addpenalty{-\@lowpenalty}%
\addvspace\bigskipamount
\def\par{% first half of "\@setpar"
{\@@par}%
\hangafter \z@
\def\par{{\@@par}}%
}%
\def\@par{{\@@par}}% second half of "\@setpar"
\@hangfrom{\textbf{#1}\enspace}%
\ignorespaces
}{%
\@@par
\addpenalty{-\@lowpenalty}%
\addvspace\bigskipamount
}
\makeatother
\begin{document}
Some text before the labeled material: it ought to be long enough to show where
the right margin lies.
\bigskip
\mySingleParHangFrom{Sample label:}
This paragraph has the desired hanging indentation.
Note that \emph{no space} should be used at the end of the argument of the
\verb|\mySingleParHangFrom| command.
But how do we tell \LaTeX\ where to stop the hanging indentation?
Well, we do so simply by ending the paragraph.
\bigskip
As you can see, normal margins resume when we start a new paragraph. Of course,
this entails that the \verb|\mySingleParHangFrom| cannot be used when we want
the hanging indentation to last across several paragraphs; for this, the
\texttt{myHangFrom} environment is provided. Note that this environment
automatically adds some amount of vertical space above and below its contents.
\begin{myHangFrom}{Sample label:}
Note that \emph{no space} should be used at the end of the argument of the
\texttt{myHangFrom} environment. Some more text, and even more.
At this point, \( \verb|\hangindent| = \texttt{\the\hangindent} \)
and \( \verb|\hangafter| = \number\hangafter \).
As you can see here, all subsequent paragraphs inside
the \texttt{myHangFrom} environment have hanging indentation too, but this
time the indentation starts at the first line: this is because, now,
\( \verb|\hangafter| = \number\hangafter \)
(while \( \verb|\hangindent| = \texttt{\the\hangindent} \),
the same as before).
\medskip
You are allowed to insert vertical space between the paragraphs without
interfering with this feature.
A fourth paragraph, which is just two lines long.
(Is it? Yes, \emph{now} it is!)
And a fifth.
\end{myHangFrom}
Some text after the labeled material. As expected, the normal margins are again
in force at this point.
\end{document}
它产生的输出:
有关进一步解释,请参阅TeXbook,第 102-103 页。
答案2
\documentclass[12pt]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[turkish,english,shorthands=:!]{babel}
\usepackage{apacite}
\usepackage[a4paper,left=30mm,top=30mm,right=25mm,bottom=25mm]{geometry}
\usepackage{epigraph}
\usepackage{graphicx}
\usepackage{float}
\usepackage{mathptmx}
\usepackage[titletoc,title]{appendix}
\usepackage{afterpage}
\usepackage[doublespacing]{setspace}
\usepackage{tocloft}
\usepackage{url}
\usepackage{indentfirst}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{longtable}
\usepackage{lipsum}
\usepackage{tabularx} % <-- added
\begin{document}
\thispagestyle{plain}
\phantomsection
\begin{center}
Yüksek Lisans Tezi\\
\singlespacing %\doublespacing
\addcontentsline{toc}{chapter}{ÖZET}
{\fontsize{12pt}{12pt}\selectfont \textbf{\MakeUppercase{Özet}}}\\
\vspace{\baselineskip}
THESIS NAME\\
\singlespacing
Writer's Name\\
\singlespacing
Teknik Üniversitesi\\
Fen Bilimleri Enstitüsü\\
A Anabilim Dalı\\
Danışman: Dr. John DOE\\
2019, 100 (Tez Sayfa), 5 (Ek Sayfalar)
\end{center}
%%% Özet
\par Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\\
\singlespace
\noindent
\begin{tabularx}{\linewidth}{@{}lX@{}}
\textbf{Anahtar Kelimeler}: & Ullamco Laboris Nisi, Aliquip, Commodo, Consequat, Duis, Aute, Irure Dolor Reprehenderit, Voluptate, Velit, Vsse, Cillum, Dolore Deu Fugiat, Nulla, Pariatur, Excepteur, Sint, Occaeca Cupidatat, Proident
\end{tabularx}
\clearpage
\end{document}
答案3
无需任何包,您可以使用\parbox
:
\documentclass{article}
\usepackage{lipsum,parskip} % only for the mwe
\begin{document}
\lipsum[2]
\noindent{\bfseries Anathar Kelimeler:}\hfill
\parbox[t]{.7\linewidth}{\lipsum[11]}
\lipsum[4]
\end{document}