我想将文档中的某些行分成 3 个部分,使得每个部分的首字母始终位于另一个部分的正下方,有点像表格,但我不想使用表格环境。
我当前的代码是:
\documentclass[11pt,a4paper]{scrreprt}
\pagenumbering{gobble}
\usepackage[english]{babel}
\linespread{1.25}
\usepackage[top=1.5cm, bottom=1cm, left=1.25cm, right=1.25cm]{geometry}
\usepackage{changepage}
\begin{document}
\normalsize\textbf{Book title}\hspace{3.3cm}\textbf{Author's name}\hspace{5.4cm} 2010\\
\hangindent=4.25cm
\hangafter=0 This book is about some guy who wrote a book because he felt like a book would be a good thing to write.....etc etc etc
\normalsize\textbf{Book title 2}\hspace{3.1cm}\textbf{Longer Author's name}\hspace{4.9cm} 1991\\
\hangindent=4.25cm
\hangafter=0 This book is about a woman.....etc etc
\end{document}
如您所见,我已将 \hspace 命令放置在行中间以产生所需的间距,但对于许多条目来说,这样做非常繁琐。有没有更好的方法,不需要使用表格环境?
答案1
使用该包的一种非表格方法tabto
:
\documentclass[11pt,a4paper]{scrreprt}
\usepackage{tabto}
\parindent0pt
\parskip.5em
\begin{document}
\NumTabs{3}
\noindent {\bfseries Book title} \tab{\bfseries Author's name} \tab{2010}
This book is about some guy who wrote a book because he felt like a book would be a good thing to write.....etc etc etc
{\bfseries Book title 2} \tab{\bfseries Longer Author's name} \tab{1991}
This book is about a woman\ldots etc. etc.
\end{document}
但是请注意,如果名称很长,这种方法可能不正确。在这种情况下,您可以使用\parbox
和\hfill
。例如:
\documentclass[11pt,a4paper]{scrreprt}
\def\tab#1{\parbox[t]{.3\linewidth}{#1}\hfill}
\parindent0pt
\parskip.5em
\begin{document}
\tab{\bfseries Book title} \tab{\bfseries Author's name} \tab{2010}
This book is about some guy who wrote a book because he felt like a book would be a good thing to write.....etc etc etc
\tab{\bfseries Book title 2} \tab{\bfseries Very very very long Author's name} \tab{1991}
This book is about a woman\ldots etc. etc.
\end{document}
答案2
您可以使用\makebox
来指定块的宽度。正如其他答案所示,还有其他框命令可以为您提供其他选项,例如文本换行(请参阅texdoc lshort
)。如果您希望日期向右对齐,只需在\hfill
日期前面加上一个即可。
如果您定义一个宏来分隔和格式化您的标题以便您可以使用语义标记,那么这一切都会变得更简单。
\documentclass{article}
\usepackage{lipsum}
\newcommand{\pubTitleAuthorYear}[3]{%
\noindent%
\makebox[0.5\linewidth][l]{\textbf{#1}}% book title
\makebox[\width][l]{\textbf{#2}}% author name
\hfill%
#3% year
\smallskip\par%
}
\newcommand{\pubInfo}[1]{\noindent #1\medskip\par}
\begin{document}
\pubTitleAuthorYear{Book One}{Author One}{2010}
\pubInfo{\lipsum[1]}
\pubTitleAuthorYear{Book Two}{Author Two}{2011}
\pubInfo{\lipsum[2]}
\end{document}
如果您希望更轻松地配置布局,您可以用单独的宏替换框的宽度及其内容的格式。例如,\newlength{\bookTitleWidth} \setlength{\bookTitleWidth}{0.5\textwidth}
和\newcommand{\bookTitleFont}[1]{\textbf{\emph{#1}}}
。