如何正常使用 \par 并缩小规则与文本之间的距离?

如何正常使用 \par 并缩小规则与文本之间的距离?
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[demo]{graphicx}

\newcommand\crule[3][black]{\textcolor{#1}{\rule{#2}{#3}}}

\newenvironment{complement}[1]
    {\begin{center}
        \begin{minipage}{\textwidth}
        \textbf{#1}\\
        \crule[Blue]{\textwidth}{0.1ex}             
    }{
       \end{minipage}
       \end{center}}    

\begin{document}
    \begin{complement}{story}
   \par He was an Austrian physicist famous for his founding contributions in the fields of
    statistical mechanics and statistical thermodynamics.
    \par He was one of the most important advocates for atomic theory at a time when that scientific model was 
    still highly controversial.\\
    \end{complement}

\end{document}

我希望文字“story”位于规则上,规则与规则下方的文字之间的距离变窄,并且命令“\par”可以缩进文字。

在此处输入图片描述

答案1

如果您想要该行下方有更多空间,请取消注释我所注释的行,并使用 参数进行操作\\

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[demo]{graphicx}

\newcommand\crule[3][black]{\textcolor{#1}{\rule{#2}{#3}}}

\newenvironment{complement}[1]
    {
        \centering
        \begin{minipage}{\textwidth}
        \parindent 1em\relax
        \parskip 0pt\relax
        \noindent\textbf{#1}\\[-8pt]
        \crule[Blue]{\textwidth}{0.1ex}
%        \\[-8pt]% ADJUST SPACE BELOW LINE
        \par          
    }{
       \end{minipage}
    }    

\begin{document}
    \begin{complement}{story}
   \par He was an Austrian physicist famous for his founding contributions in the fields of
    statistical mechanics and statistical thermodynamics.
    \par He was one of the most important advocates for atomic theory at a time when that scientific model was 
    still highly controversial.\\
    \end{complement}

\end{document}

在此处输入图片描述

答案2

我建议直接使用\hrule,这样可以更好地控制周围的垂直间距。

\documentclass{article}
\usepackage[dvipsnames]{xcolor}

\newenvironment{complement}[1]{%
  \begin{center}
  \begin{minipage}{\textwidth}
  \textbf{#1}{\color{Blue}\par
  \vspace{0.5ex}
  \hrule height 0.1ex}
  \vspace{0.5ex}
}{\end{minipage}
  \end{center}
}

\begin{document}

\begin{complement}{story}
He was an Austrian physicist famous for his founding contributions
in the fields of statistical mechanics and statistical thermodynamics.

He was one of the most important advocates for atomic theory at
time when that scientific model was still highly controversial.
\end{complement}

\end{document}

我会\par在文档中避免使用它:它会导致尴尬的标记。

在此处输入图片描述

答案3

这说明了核心 TeX 命令 的使用\hrule\rule以水平模式运行(在段落内),\hrule以垂直模式运行(在段落之间),并且不添加任何额外空间(甚至没有\lineskip)。

值得注意的是,的默认宽度为\hrule\textwidth实际上\hsize),默认高度为\linewidth

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[demo]{graphicx}

\newcommand\crule[3][black]{\textcolor{#1}{\hrule  width#2 height#3}}

\newenvironment{complement}[1]
    {
        \centering
        \begin{minipage}{\textwidth}
        \parindent 1em\relax
        \parskip 0pt\relax
        \noindent\textbf{#1}
        \crule[Red]{\textwidth}{.1ex}%
        \medskip% optional
    }{
       \end{minipage}
    }    

\begin{document}
    \begin{complement}{story}
   \par He was an Austrian physicist famous for his founding contributions in the fields of
    statistical mechanics and statistical thermodynamics.
    \par He was one of the most important advocates for atomic theory at a time when that scientific model was 
    still highly controversial.\\
    \end{complement}

\end{document}

答案4

喜欢这个吗?我重新定义了 \ crule 以添加第二个可选参数xparse

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[demo]{graphicx}
\usepackage{xparse}

\NewDocumentCommand{\crule}{O{black}o m m}{{\color{#1}\IfNoValueTF{#2}{\rule{#3}{#4}}{\rule[#2]{#3}{#4}}}}
\newenvironment{complement}[1]
    {\begin{center}
        \begin{minipage}{\textwidth}
        \textbf{\rlap{\crule[Blue][-0.6ex]{\textwidth}{0.1ex}}#1}\medskip\par\hspace{\parindent}
%
    }{
       \end{minipage}
       \end{center}}

\begin{document}

    \begin{complement}{story}
   He was an Austrian physicist famous for his founding contributions in the fields of
    statistical mechanics and statistical thermodynamics.
    \par He was one of the most important advocates for atomic theory at a time when that scientific model was
    still highly controversial.\\
    \end{complement}

\end{document} 

在此处输入图片描述

相关内容