(La)TeX 相当于 MS Word 的“不要在相同样式的段落之间添加空格”

(La)TeX 相当于 MS Word 的“不要在相同样式的段落之间添加空格”

我使用quote环境通过两个自定义命令在章节开头添加一些引用。如果我有多个引用,\list环境会自动在每个引用周围添加边距,这看起来不太美观。微软 Word提供段落选项“不要在相同风格的段落之间添加空格“这将能够抑制这两个环境之间的空间。 在这种情况下我该怎么做同样的事情?

梅威瑟:

\documentclass{article}

\usepackage{url}
\usepackage{blindtext}

% Commands for adding references to sections
\newcommand{\referenceurl}[2][See:]{\begin{quote}\emph{#1} \url{#2}\end{quote}}
\newcommand{\reference}[2][See:]{\begin{quote}\emph{#1} #2\end{quote}}

\begin{document}
\section{Important Material}
\referenceurl{http://www.example.com/important_material}
\reference[See also:]{\emph{Important Material for Dummies}, Wikipedians Anonymous Press, 2005.}
\blindtext

\section{Other Material: Ideal Style}
\referenceurl{http://www.example.com/important_material}
\reference[\vskip -6ex\relax See also:]{\emph{Important Material for Dummies}, Wikipedians Anonymous Press, 2005.}
\blindtext

\section{Single Reference: Default style should not change}
\reference{Example page}
\blindtext

\section{Single URL Reference: Default style should not change}
\referenceurl[Excellent Resource:]{http://www.example.com/important_material}
\blindtext

\section{Multiple References: Spacing should be suppressed}
\reference{Textbook}
\reference[Alternate Resource:]{Textbook}
\blindtext
\end{document}

答案1

我建议你为此设置一个专用的列表环境。这样,条目就只是\items 而已,不需要特殊命令。使用包设置此类列表最容易enumitem

示例输出

\documentclass{article}

\usepackage{url,enumitem}
\usepackage{blindtext}

\newlist{references}{itemize}{1}
\setlist[references]{align=left,leftmargin=2em,itemindent=!,rightmargin=2em,labelindent=2em,labelsep=0.3em,itemsep=0pt,parsep=0pt,label=See:,font=\normalfont\textit}

\begin{document}
\section{Important Material}
\begin{references}
  \item \url{http://www.example.com/important_material}
  \item[See also:]{\emph{Important Material for Dummies},
  Wikipedians Anonymous Press, 2005.}
\end{references}
\blindtext

\section{Other Material: Ideal Style}
\begin{references}
  \item \url{http://www.example.com/important_material}
  \item[See also:]{\emph{Important Material for
  Dummies}, Wikipedians Anonymous Press, 2005.}
\end{references}
\blindtext

\end{document}

答案2

您可以检测到并自动删除空格,但我不会这样做,我会使用更明确的标记:

\documentclass{article}

\usepackage{url}
\usepackage{blindtext}

% Commands for adding references to sections
\newcommand{\referenceurl}[2][See:]{\par\emph{#1} \url{#2}}
\newcommand{\reference}[2][See:]{\par\emph{#1} #2}
\newenvironment{secrefs}{\quote\parskip0pt\relax}{\endquote}
\begin{document}
\section{Important Material}
\begin{secrefs}
\referenceurl{http://www.example.com/important_material}
\reference[See also:]{\emph{Important Material for Dummies}, Wikipedians Anonymous Press, 2005.}
\end{secrefs}
\blindtext

\section{Other Material: Ideal Style}
\begin{secrefs}
\referenceurl{http://www.example.com/important_material}
\reference[See also:]{\emph{Important Material for Dummies}, Wikipedians Anonymous Press, 2005.}
\end{secrefs}
\blindtext

\end{document}

相关内容