1
\documentclass{article} \makeatletter \newenvironment{myquote}[1]{% % to change text size, say to small % add \small before \par in the next line \par\addvspace{2ex} \if@nobreak % we're at the start of a section % add the indent \if@afterindent\else\hspace*{\parindent}\fi % and instruct LaTeX to reset \@afterheading at the end \def\reset@nobreakatend{\@afterheading}% \else \def\reset@nobreakatend{}% \fi \begin{minipage}{\dimexpr\linewidth -2\parindent\relax}% \def\myquoteauthorname{#1}% }{% \par\vspace{0.2ex} \noindent \hspace*{0.25\linewidth}% \rule{0.5\linewidth }{.4pt} \par\addvspace{1ex} \centering \textbf{\myquoteauthorname}\par\vspace{1ex} \end{minipage} \par\nobreak\reset@nobreakatend} \makeatother \begin{document} \begin{myquote}{Diane Ravitch} The person who knows ``how'' will always have a job. The person who knows ``why'' will always be his boss. \end{myquote} \begin{myquote}{Diane Ravitch} \centering The person who knows ``how'' will always have a job. The person who knows ``why'' will always be his boss. \end{myquote} \begin{myquote}{Diane Ravitch} \begin{center} The person who knows ``how'' will always have a job. The person who knows ``why'' will always be his boss. \end{center} \end{myquote} \end{document} 

enter image description here

In the code above (original answer by @egreg), I want to center the text inside the minipage. If I use \centering the rule moves; if I use \begin{center} \end{center}, I get vertical space.

  1. How can I center the text without moving the rule and not have extra vertical space?
  2. How can have an alternate version of myquote where text is centered? (I tried to place \centering inside at various points, but in all of them the rule has also moved.)

1 Answer 1

2

I'd say the easiest solution is to add an additional group which restricts the effect of whatever declaration you write in the environment body

\documentclass{article} \makeatletter \newenvironment{myquote}[1]{% % to change text size, say to small % add \small before \par in the next line \par\addvspace{2ex} \if@nobreak % we're at the start of a section % add the indent \if@afterindent\else\hspace*{\parindent}\fi % and instruct LaTeX to reset \@afterheading at the end \def\reset@nobreakatend{\@afterheading}% \else \def\reset@nobreakatend{}% \fi \begin{minipage}{\dimexpr\linewidth -2\parindent\relax}% \def\myquoteauthorname{#1}% \begingroup % <-- ADD THIS }{% \par\endgroup\vspace{0.2ex} % <-- ADD \endgroup HERE \noindent \hspace*{0.25\linewidth}% \rule{0.5\linewidth }{.4pt} \par\addvspace{1ex} \centering \textbf{\myquoteauthorname}\par\vspace{1ex} \end{minipage} \par\nobreak\reset@nobreakatend} \makeatother \begin{document} \begin{myquote}{Diane Ravitch} \centering The person who knows ``how'' will always have a job. The person who knows ``why'' will always be his boss. \end{myquote} \begin{myquote}{Diane Ravitch} \itshape The person who knows ``how'' will always have a job. The person who knows ``why'' will always be his boss. \end{myquote} \end{document} 

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.