1

Following the answer to another question of mine, which had custom minipage settings for quotes,

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[
    a6paper,
    showframe,
]{geometry}

\newenvironment{myquote}[1]{%
  \par
  \begin{minipage}{\dimexpr\textwidth-2\parindent\relax}%
    \def\myquoteauthorname{#1}%
  }{%
    \par\vspace{1ex}
    \noindent
    \hspace*{0.25\textwidth}%
      \rule{0.5\textwidth}{.4pt}
    \par\vspace{1ex}
    \centering
    \textsc{\myquoteauthorname}\par
  \end{minipage}
  \par}

\begin{document}

\begin{myquote}{Robert Kleinhenz}
    When asked what it was like to set about proving something, the mathematician
  likened proving a theorem to seeing the peak of a mountain and trying to climb
  to the top. One establishes a base camp and begins scaling the mountain's sheer
  face, encountering obstacles at every turn, often retracing one's steps and
  struggling every foot of the journey. Finally when the top is reached, one
  stands examining the peak, taking in the view of the surrounding countryside
  and then noting the automobile road up the other side!
\end{myquote}

\end{document}

and which would output:

enter image description here

For two-column paper, I replaced \textwidth with \columnwidth to have:

\documentclass[12pt, twocolumn]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[
    a4paper,
    showframe,
]{geometry}

\newenvironment{myquotecolumn}[1]{%
  \par
  \begin{minipage}{\dimexpr\columnwidth -2\parindent\relax}%
    \def\myquoteauthorname{#1}%
  }{%
    \par\vspace{1ex}
    \noindent
    \hspace*{0.25\columnwidth }%
      \rule{0.5\columnwidth }{.4pt}
    \par\vspace{1ex}
    \centering
    \textsc{\myquoteauthorname}\par
  \end{minipage}
  \par}  

\begin{document}

\begin{myquotecolumn}{Robert Kleinhenz}
    When asked what it was like to set about proving something, the mathematician
  likened proving a theorem to seeing the peak of a mountain and trying to climb
  to the top. One establishes a base camp and begins scaling the mountain's sheer
  face, encountering obstacles at every turn, often retracing one's steps and
  struggling every foot of the journey. Finally when the top is reached, one
  stands examining the peak, taking in the view of the surrounding countryside
  and then noting the automobile road up the other side!
\end{myquotecolumn}

\end{document}

which would output:

enter image description here

Is it somehow possible to combine them? That I have one environment and it adjusts itself whether it is single column or two columns?

blackened
  • 4,181
  • 1
    Does the version using \columnwidth cause any problem in a one-column document? – frougon Jul 17 '19 at 09:32
  • 2
    Have you tried to use \linewidth in the closing part of the environment, instead of \textwidth or \columwidth ? – Jhor Jul 17 '19 at 09:33
  • 1
    @blackened Most of the time, I use \linewidth, but there is a difference between \linewidth and \columnwidth inside list environments (see Difference between \textwidth, \linewidth and \hsize). I don't know why so many people use \textwidth all the time... This is a matter of intended use, but without more info, I believe I'd use \linewidth here too (inside a list environment, the minipage would be centered within an item's width). – frougon Jul 17 '19 at 09:45

1 Answers1

2

You can simply use the second definition, as \columnwidth is the same as \textwidth in one-column mode. Actually, I would probably use \linewidth. This way, in case you use your environment inside a list item (itemize, etc.), the minipage will be centered within that item (and the rule length adapted to its width). This is a matter of taste, of course (what you expect in such use cases is your call). The difference with \columnwidth can be quite visible if you use the environment in deeply-nested lists: \columnwidth won't change and will remain larger than \linewidth, which is going to decrease with each nesting level.

See Difference between \textwidth, \linewidth and \hsize for a precise description of these various parameters, most notably TeX's \hsize and LaTeX's \textwidth, \columnwidth and \linewidth.

frougon
  • 24,283
  • 1
  • 32
  • 55