1
\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[
    paperwidth=32pc,%
    paperheight=48pc,%
    margin=4pc,%
]{geometry}

\begin{document}

\begin{center}
\vspace{3ex}
    \begin{minipage}{0.75\textwidth}
    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!

    \vspace{1ex}
    \centering
     \noindent\hfil\rule{0.5\textwidth}{.4pt}\hfil

    \vspace{1ex}
    \textsc{Robert Kleinhenz}
    \end{minipage}    
\vspace{3ex}
\end{center} 

\end{document}

enter image description here

  1. How can I make the width of the minipage such that there is a \parindent margin from both left and right. I tried \begin{minipage}{\textwidth-\parindent}-\parindent (with the calc package) but it did not do anything.
  2. Why the horizontal rule is not centered inside the minipage?
  3. How can I turn this setup to a command? (So I simply write something like \myquote{This is a quote.}{---From somebody}
blackened
  • 4,181
  • If you want to have \parindent on the left and on the right, the minipage width ought to be \textwidth-2\parindent, not \textwidth-\parindent... right? – frougon Jun 26 '19 at 12:16

1 Answers1

2

You need \dimexpr to have the minipage evaluate the expression, and then \dimexpr\textwidth-2\parindent.

The rule was not centered because you had \centering active and \hfil\rule{}{}\hfil, but TeX discards glue (which includes \hfil) at the end of a line, so the last \hfil was removed. And with \centering you have \leftskip and \rightskip doing \hfil, so you had 2 \hfil to the left and one to the right, thus the misalignment.

The simplest case to make that into a command is with \newcommand\myquote[2]. If you want additional settings to this quote environment you might need to add an optional argument and a keyval parser to set some options.

I changed the page layout for the example, but you can change back.

enter image description here

\documentclass[12pt]{article}

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

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

\begin{document}

\myquote{
  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!
}{Robert Kleinhenz}

\end{document}

Here's an alternative definition to have the rule be the same width as the name of the author of the quote:

\makeatletter
\newcommand\myquote[2]{%
  \par
  \begin{minipage}{\dimexpr\textwidth-2\parindent\relax}
    #1
    \par\vspace{1ex}
    \noindent
    \settowidth\dimen@{\textsc{#2}}%
    \ifdim\dimen@>\textwidth
      \dimen@\textwidth
    \fi
    \hspace*{0.5\dimexpr\textwidth-\dimen@}%
      \rule{\dimen@}{.4pt}
    \par\vspace{1ex}
    \centering
    \textsc{#2}\par
  \end{minipage}
  \par}
\makeatother

enter image description here

However, as daleif said in the comment, commands are usually better for shorter pieces of text. Longer ones tend to get messy. You need to balance braces across multiple lines, you need to worry about \long\defs, verbatim doesn't work anymore, and a bunch of other issues. Environments are more natural in the case of big pieces of text (in fact, quoting packages usually use environments). Here are the environment version of the commands above, both of which you use as:

\begin{myquote}{<author>}
  <quote>
\end{myquote}
% Fixed length rule
\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}
% Variable length rule
\makeatletter
\newenvironment{myquote}[1]{%
  \par
  \begin{minipage}{\dimexpr\textwidth-2\parindent\relax}%
    \def\myquoteauthorname{#1}%
  }{%
    \par\vspace{1ex}
    \noindent
    \settowidth\dimen@{\textsc{\myquoteauthorname}}%
    \ifdim\dimen@>\textwidth
      \dimen@\textwidth
    \fi
    \hspace*{0.5\dimexpr\textwidth-\dimen@}%
      \rule{\dimen@}{.4pt}
    \par\vspace{1ex}
    \centering
    \textsc{\myquoteauthorname}\par
  \end{minipage}
  \par}
\makeatother
  • Wouldn't it be cleaner as an environment where you give the person as an argument to the env, macros with long arguments are often very messy – daleif Jun 26 '19 at 13:46
  • 1
    @daleif It certainly would... I just did the macro at OP's request. I'll add an environment version, though. – Phelype Oleinik Jun 26 '19 at 13:48