![从此行开始下一个段落](https://linux22.com/image/268852/%E4%BB%8E%E6%AD%A4%E8%A1%8C%E5%BC%80%E5%A7%8B%E4%B8%8B%E4%B8%80%E4%B8%AA%E6%AE%B5%E8%90%BD.png)
总结:我可以说服 LaTeX 在与当前段落相同的行上开始下一个段落吗?
我为简历选择的格式如下:
经验
Doctor Midos, Inc. 1988 年 1 月至 6 月
Midos 机器操作员:将 sanafratz 连接到 grepsling,并对 whizding 进行超负荷运转。
检查 kugelator 中是否有松动的电线。
K'fitsas Haderech 机器飞行员:巧妙地使用激光枪吹出一个巨大的泡泡糖泡泡。
在 Doomstein 空间站上演大胆的救援行动。
我开发的代码如下所示:
\documentclass{article}
% Short (i.e., one- to two-line) items
\newcommand*{\ritem}{\par}
% Short item with inline header
\newcommand*{\rnote}[1]{\par\textit{#1}:}
% Job title, to be followed by an \ritem-list of accomplishments, responsibilities, etc.
\newcommand*{\rposition}[1]{%
\renewcommand*{\ritem}{\relax\renewcommand*{\ritem}{\par}}%
\rnote{#1}%
}
\setlength{\parindent}{0in}
\begin{document}
\section{Experience}
\textbf{Doctor Midos, Inc.} \hfill \textbf{January--June 1988}
\rposition{Midos Machine Operator}
\ritem Connected the sanafratz to the grepsling and
hypercharged the whizding.
\ritem Checked for loose wires in the kugelator.
\rposition{K'fitsas Haderech Machine Pilot}
\ritem Blew a giant bubble-gum bubble
by ingenious use of a laser gun.
\ritem Staged rescue on Space Station Doomstein.
\end{document}
与格式化的示例一样,第一个宏\ritem
从位置描述同一行开始,因为宏的扩展是\relax
;第二个宏(以及后续宏)将从新行开始,因为第一个调用已将自身重新定义为\par
。
重新定义为重新定义自身的部分\ritem
感觉有点恶心,我希望能够摆脱它。但这需要宏以\rposition
某种方式指示下一个段落应该从其自身所在的同一行开始——这可能吗?
答案1
你可以使用条件语句。以下是使用的一些(重新)定义etoolbox
:
\usepackage{etoolbox}
\providebool{nopar}
\renewcommand{\rposition}[1]{%
\rnote{#1}%
% set 'nopar' = true
\booltrue{nopar}}
\renewcommand{\ritem}{%
\ifbool{nopar}%
% if nopar = true, do nothing except set 'nopar' false
{\boolfalse{nopar}}%
% if nopar = false, start a new paragraph and keep 'nopar' (redundantly) false
{\par\boolfalse{nopar}}%
}
答案2
你可以提前查看是否\ritem
后面跟着\rposition
(using \@ifnextchar
)。如果是,就直接吞掉它 (using \@gobble
)。当然,如果总是后面跟着一个\ritem
,你就可以不管它而直接吞掉它。下面是使用第一种(条件)方法的方法:
\documentclass{article}
% Short (i.e., one- to two-line) items
\newcommand*{\ritem}{\par}
\makeatletter
% Short item with inline header
\newcommand*{\rnote}[1]{\par\textit{#1}:\@ifnextchar\ritem{\space\@gobble}\relax}
\makeatother
% Job title, to be followed by an \ritem-list of accomplishments, responsibilities, etc.
\newcommand*{\rposition}[1]{%
\rnote{#1}%
}
\setlength{\parindent}{0in}
\begin{document}
\section{Experience}
\textbf{Doctor Midos, Inc.} \hfill \textbf{January--June 1988}
\rposition{Midos Machine Operator}
\ritem Connected the sanafratz to the grepsling and
hypercharged the whizding.
\ritem Checked for loose wires in the kugelator.
\rposition{K'fitsas Haderech Machine Pilot}
\ritem Blew a giant bubble-gum bubble
by ingenious use of a laser gun.
\ritem Staged rescue on Space Station Doomstein.
\end{document}