在Word中很容易获得以下结果:
在 Latex 中如何实现这一点?
描述:
- 第一行不缩进,制表符固定在 2 cm 处
- 从第二行开始,缩进2厘米
也就是说,如果第一列足够短,那么就会有一个制表符(或跳转到第二列),否则行会延伸到第二列,并由逗号+空格分隔。
词汇表能处理这样的事情吗?最后应该结合我的帖子在这里。
答案1
您可以使用以下方式获得结果enumitem
:
\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum}
\newlength{\commalabelwd}
\newcommand{\commalabel}[2]{%
\settowidth\commalabelwd{\normalfont\itshape#2,\hspace{\labelsep}}%
\normalfont\itshape#2\ifdim#1<\commalabelwd,\fi\hfill
}
\begin{document}
\begin{description}[
labelwidth=\dimexpr2cm-\labelsep,
leftmargin=2cm,
before={\renewcommand\makelabel[1]{\commalabel{2cm}{##1}}}
]
\item[Short] \lipsum[1][1-2]
\item[Longer] \lipsum[1][1-2]
\item[Longerr] \lipsum[1][1-2]
\item[Longerrr] \lipsum[1][1-2]
\item[Longerrrr] \lipsum[1][1-2]
\item[Longerrrrr] \lipsum[1][1-2]
\item[Longerrrrrr] \lipsum[1][1-2]
\item[Longerrrrrrr] \lipsum[1][1-2]
\item[Longerrrrrrrrrrrrr] \lipsum[1][1-2]
\end{description}
\end{document}
答案2
不久前,我不得不解决完全相同的问题。方法与 frougon 类似:
\documentclass{article}
\usepackage[papersize={5.5in,8.5in}]{geometry}
\usepackage{lipsum}
%% Change the optional argument to suit -- 1in in this case
\newcommand{\hangit}[2][1in]{%
\hangindent#1
\setbox0=\hbox{\itshape#2\space}
\noindent
\ifdim\wd0>\myhang
\textit{#2,}\space
\else
\hbox to #1{\box0\hfill}%
\fi
\ignorespaces
}
%% #1 default indent; #2 text in indent; #3 main text; #4 text after dot leaders
\newcommand{\hangitpar}[4][1in]{%
\hangindent#1
\setbox0=\hbox{\itshape#2\space}
\noindent
\ifdim\wd0>\myhang
\textit{#2,}\space
\else
\hbox to #1{\box0\hfill}%
\fi
#3\mindotfill#4%
}
\newcommand{\mindotfill}{%
\nolinebreak
{\def\hfill{\hskip 1cm plus 1fill\relax}%
\dotfill
}%
}
%% Same, but uses an argument delimited with a +
%% Requires \newlength{\myhang}
%% Could also be given explicitely in the \def
\newlength{\myhang}
\setlength{\myhang}{1in}
\def\hhangit#1+{%
\hangindent\myhang
\setbox0=\hbox{\itshape#1\space}
\noindent
\ifdim\wd0>\myhang
\textit{#1,}\space
\else
\hbox to \myhang{\box0\hfill}%
\fi
\ignorespaces
}
\begin{document}
\lipsum[5][1-4]
\hangitpar{A longer test of sorts}{\lipsum[7][4-7]}{123}
\hangit{First one}\lipsum[3][4-7]
%% Use of optional argument:
\hangit[0.75in]{Second is a bit longer}\lipsum[8][4-7]
%% Use of + delimited argument:
\hhangit And this is the next longer+ \lipsum[9][4-7]\mindotfill 123
\lipsum[6][1-4]
\end{document}
更新
楼主对点引线的要求终于被我理解了。我相应地修改了代码和示例。代码\mindotfill
取自 frougon 在调整自定义符号表的点填充
答案3
你可以这样做:
\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\newlength{\myColWidth}
\setlength{\myColWidth}{4em}
\newlength{\myColSep}
\setlength{\myColSep}{1em}
% A comma is appended if, and only if \widthof{#1} >= \myColWidth-\myColSep.
% The second column always starts at \myColWidth from the left margin. In
% other words, \myColSep is internal to the first column.
\newenvironment{conceptEntry}[1]{%
\smallskip\par\noindent
\hangindent=\myColWidth\hangafter=1\relax
\setbox0=\hbox{#1}%
\ifdim\wd0<\dimexpr \myColWidth-\myColSep \relax
\hbox to \myColWidth{\box0\hfil}%
\else
\setbox0=\hbox{\box0, }%
\ifdim\wd0<\myColWidth
\hbox to \myColWidth{\box0\hfil}%
\else
\box0\relax
\fi
\fi
\ignorespaces
}{%
\par
\ignorespacesafterend
}
\newcommand*{\showCommaThreshold}{%
\par\noindent
\begingroup
\color{blue}%
\rule{\dimexpr \myColWidth-\myColSep\relax}{1pt}%
\endgroup
}
\begin{document}
The entry text (\emph{Lorem ipsum} here) starts precisely at
\verb|\myColWidth| from the left margin. In blue, we show the tunable
threshold for the entry key width, after which a comma is appended (its value
is \verb|\myColWidth-\myColSep|):
\showCommaThreshold
\begin{conceptEntry}{Short}
\lipsum[1][1-4]
\end{conceptEntry}
\showCommaThreshold
\begin{conceptEntry}{Longe.}
\lipsum[1][1-4]
\end{conceptEntry}
\showCommaThreshold
\begin{conceptEntry}{Longer}
\lipsum[1][1-4]
\end{conceptEntry}
\begin{conceptEntry}{Even longer}
\lipsum[1][1-4]
\end{conceptEntry}
\end{document}
对于你似乎想在之后添加的虚线,我会尝试从\@dottedtocline
(用于排版“虚线”目录条目的 LaTeX 宏中获取灵感 - 请参阅源2e.pdf)。基本思想是使用 保留段落右侧的空间\rightskip
,但这个空间可以由段落的最后一行(以点和页码或任何数字结尾)占用。以下设置就是这样的:
\rightskip \@tocrmarg \parfillskip -\rightskip
确保在的定义中\@dottedtocline
,其中\@tocrmarg
是
多行条目的最后一行以外所有行的右边距缩进
(引自源2e.pdf)。