2
\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}

I want that the text "story" sits on the rule, the distance between the text below the rule and rule gets narrower, and the command "\par" can indent text.

enter image description here

K.Robert
  • 421
  • For reference, I find an elegant way to reset the \parindent similiar to the method that resets \parskip. https://tex.stackexchange.com/questions/43002/how-to-preserve-the-same-parskip-in-minipage – K.Robert Sep 14 '17 at 12:53

4 Answers4

1

If you want more space below the line, uncomment my commented line and play with the argument to \\.

\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}

enter image description here

1

I suggest using directly \hrule, which allows for finer control over the vertical spacing around it.

\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}

I'd avoid \par in the document: it makes for awkward markup.

enter image description here

egreg
  • 1,121,712
1

This illustrates the use of core TeX command \hrule. Whereas \rule runs in horizontal mode (inside a paragraph), \hrule runs in vertical mode (between paragraphs) and adds no additional space (not even \lineskip).

It should be noted that the default width for \hrule is \textwidth (actually \hsize) and the default height is \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}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
0

Like this? I redefined \ crule to add a second optional argument with 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} 

enter image description here

Bernard
  • 271,350