0

I am having trouble understanding how to fix this.

I have a latex command for a block-quote, that I found somewhere else on this site. The sentence I want to quote, however, is stretched on two lines. I spotted that the geometry package plays a role to some extent in this.

\documentclass [10.5pt]{book}

\usepackage{geometry}

\usepackage{csquotes} \usepackage{xcolor}

% https://tex.stackexchange.com/questions/16964/block-quote-with-big-quotation-marks \newcommand{\quotebox}[2]{ \begin{center}\fcolorbox{white}{blue!15!gray!15}{ \begin{minipage}{0.95\linewidth}\vspace{10pt} \center \begin{minipage}{0.95\linewidth} {\space\Huge``}{#1}{\hspace{1.5em}\break\null\Huge\hfill''} \end{minipage} \smallbreak {#2} \end{minipage}} \end{center} }

\begin{document}

\quotebox{Usually one approaches an optimization problem presupposing that $x^\star$ exists, is unique, and is located by the method to be used.}{R. Fletcher, \textit{Practical optimization methods}}

\end{document}

And the output is:

enter image description here

where I'd like to get something like this (I can get it without the geometry package in this code snippet, but I'd like to be able to force such output with the geometry package.

enter image description here

How to avoid such stretching ?

2 Answers2

3

First, a Diagnosis

Your idea that geometry is to blame is not entirely correct. What geometry did is to exacerbate the issue, which was already present in your original code.

Consider the following code

\documentclass{book}

%\usepackage{geometry}

\usepackage{csquotes} \usepackage{xcolor}

% https://tex.stackexchange.com/questions/16964/block-quote-with-big-quotation-marks \newcommand{\quotebox}[2]{ \begin{center}\fcolorbox{white}{blue!15!gray!15}{ \begin{minipage}{0.95\linewidth}\vspace{10pt} \center \begin{minipage}{0.95\linewidth} {\space\Huge``}{#1}{\hspace{1.5em}\break\null\Huge\hfill''} \end{minipage} \smallbreak {#2} \end{minipage}} \end{center} }

\begin{document}

\quotebox{Cogito ergo sum.}{R. Descartes}

\quotebox{Usually one approaches an optimization problem presupposing that $x^\star$ exists, is unique, and is located by the method to be used.}{R. Fletcher, \textit{Practical optimization methods}}

\end{document}

Here, geometry is inactive, but you still see the horrible stretching in the first quote.

enter image description here

What geometry did is changed the margin size (the default loaded by geometry is evidently different from the default in the standard book class), and so the value of \linewidth is longer with geometry than without. So while your quote just happens to have a good length when displayed using the standard book linewidth, it looks horrible with the new linewidth given by geometry.

So what is the actual problem?

The problem is with the call to \break in the definition of your quotebox. The use of \break I believe was intentional, as one of its functions is to insert a line break and force the lines before it to be justified, inserting interword spaces. Now, if you are quoting a long piece of text, like the answer you copied from, there are usually enough words that a little bit of glue inserted here and there can make the forced justification look alright.

(In the code, it forces [together with the call to \hspace{1.5em}], the last line of the "quoted paragraph" to end exactly 1.5em away from the right.)

However, when you have a short paragraph or sentence, this forced justification can look horrible.

If you don't mind the closing quote symbol being potentially slightly far away from the end of the quote itself, one option is to replace \break with \par, as in

\newcommand{\quotebox}[2]{
    \begin{center}\fcolorbox{white}{blue!15!gray!15}{
        \begin{minipage}{0.95\linewidth}\vspace{10pt}
            \center
            \begin{minipage}{0.95\linewidth}
                    {\space\Huge``}{#1}{\hspace{1.5em}\par\vspace{-0.5em} ~\Huge\hfill''}
            \end{minipage}
            \smallbreak {#2}
        \end{minipage}}
    \end{center}
}

This produces outputs more like enter image description here which "solves" the stretching issue by replacing it with whitespace all at the end.

An Alternative

Now, I happen to like the "balanced" look provided by the original code that you showed. One way to solve this is to make the width of the quote and the width of the shaded box configurable.

This obviously will require some hand-tuning of the optimum widths (if you leave out the optional arguments, the original default from the code you shared is used). But if you like the balanced look, this amount of tuning may be worth it. (And this is only necessary for shorter quotes.)

\documentclass{book}

\usepackage{geometry}

\usepackage{csquotes} \usepackage{xcolor}

\makeatletter \newlength@OuterQuoteBoxWidth \newlength@InnerQuoteBoxWidth % Replace the old version with configurable widths \NewDocumentCommand{@quotebox}{+m m}{% \begin{center}\fcolorbox{white}{blue!15!gray!15}{ \begin{minipage}{@OuterQuoteBoxWidth}\vspace{10pt} \center \begin{minipage}{@InnerQuoteBoxWidth} {\space\Huge``}{#1}{\hspace{1.5em}\break\null\Huge\hfill''} \end{minipage} \smallbreak {#2} \end{minipage}} \end{center} } % Version to use: 4 arguements % 1 - width of outerbox (optional: default to 0.95 linewidth) % 2 - width of quote (optional: default to 0.95 of #1) % 3 - quote 4 - source \NewDocumentCommand{\quotebox}{O{0.95\linewidth} o +m m}{ \setlength@OuterQuoteBoxWidth{#1} \IfNoValueTF{#2} {\setlength@InnerQuoteBoxWidth{0.95@OuterQuoteBoxWidth}} {\setlength@InnerQuoteBoxWidth{#2}} @quotebox{#3}{#4} } \makeatother

\begin{document}

\quotebox[1.5in]{Cogito ergo sum.}{R. Descartes}

\quotebox[2.5in][1.4in]{Cogito ergo sum.}{R. Descartes, \textit{Discourse on Method}}

\quotebox[0.8\linewidth]{Usually one approaches an optimization problem presupposing that $x^\star$ exists, is unique, and is located by the method to be used.}{R. Fletcher, \textit{Practical optimization methods}}

\quotebox[0.95\linewidth][0.8\linewidth]{Usually one approaches an optimization problem presupposing that $x^\star$ exists, is unique, and is located by the method to be used.}{R. Fletcher, \textit{Practical optimization methods}} \end{document}

enter image description here

Other Comments

  • Note that the [10.5pt] is meaningless for the standard document class: the only meaningful font sizes are 10pt, 11pt, and 12pt.
Willie Wong
  • 24,733
  • 8
  • 74
  • 106
0

For long texts, balancing the quotation marks visually with the text can be done with a tabular or similar; and short texts can switch to their natural width.

Here, in expl3 as a mini-demo:

cogito

etc.

Expl3 can use keys, so allowing almost anything to become an option-setting parameter, but at some point the number of combinations and permutations in their interactions with each other becomes so exceedingly large that the ordinary mind cannot easily grasp them all in one go.

tcolorbox is more powerful, though, as it uses TikZ.

MWE

\documentclass{book}

\usepackage{geometry}

\usepackage{csquotes} \usepackage{xcolor} \usepackage{xparse} \usepackage{fontspec} \newfontfamily\fnserif{Noto Serif}

\ExplSyntaxOn

\keys_define:nn { pdqb } { framecolour .tl_set:c = { l_pd_framecolour_tl }, framecolour .default:n = { blue }, % name only is given framecolour .initial:n = { blue }, % no key % frameboxcolour .tl_set:c = { l_pd_frameboxcolour_tl }, frameboxcolour .default:n = { blue!15!green!5 }, frameboxcolour .initial:n = { blue!15!green!5 },
% outermpwidth .dim_set:c = { l_pd_outermpwidth_dim }, outermpwidth .default:n = { 0.95\linewidth }, outermpwidth .initial:n = { 0.95\linewidth },
% innermpwidth .dim_set:c = { l_pd_innermpwidth_dim }, innermpwidth .default:n = { 0.95\linewidth }, innermpwidth .initial:n = { 0.95\linewidth },
% usephrasewidth .bool_set:c = { l_pd_usephrasewidth_bool }, usephrasewidth .default:n = { false }, usephrasewidth .initial:n = { false },
% usephraseouterwidth .bool_set:c = { l_pd_usephraseouterwidth_bool }, usephraseouterwidth .default:n = { false }, usephraseouterwidth .initial:n = { false },
% topmargin .dim_set:c = { l_pd_topmargin_dim }, topmargin .default:n = { 10pt }, topmargin .initial:n = { 10pt },
% bottommargin .dim_set:c = { l_pd_bottommargin_dim }, bottommargin .default:n = { 10pt }, bottommargin .initial:n = { 10pt },
% middlemargin .dim_set:c = { l_pd_middlemargin_dim }, middlemargin .default:n = { 10pt }, middlemargin .initial:n = { 10pt },
% middlebreak .tl_set:c = { l_pd_middlebreak_tl }, middlebreak .default:n = { \smallbreak }, middlebreak .initial:n = { \smallbreak },
% lqformat .tl_set:c = { l_pd_lqformat_tl }, lqformat .default:n = { \Huge }, lqformat .initial:n = { \Huge },
% rqformat .tl_set:c = { l_pd_rqformat_tl }, rqformat .default:n = { \Huge }, rqformat .initial:n = { \Huge },
% lqmark .tl_set:c = { l_pd_lqmark_tl }, lqmark .default:n = { }, lqmark .initial:n = { },
% rqmark .tl_set:c = { l_pd_rqmark_tl }, rqmark .default:n = { '' }, rqmark .initial:n = { '' },
% leftouterformat .tl_set:c = { l_pd_leftouterformat_tl }, leftouterformat .default:n = { \begin{center} }, leftouterformat .initial:n = { \begin{center} },
% rightouterformat .tl_set:c = { l_pd_rightouterformat_tl }, rightouterformat .default:n = { \end{center} }, rightouterformat .initial:n = { \end{center} },
% leftinnerformat .tl_set:c = { l_pd_leftinnerformat_tl }, leftinnerformat .default:n = { \center }, leftinnerformat .initial:n = { \center },
% rightinnerformat .tl_set:c = { l_pd_rightinnerformat_tl }, rightinnerformat .default:n = { }, rightinnerformat .initial:n = { },
% leftsourceformat .tl_set:c = { l_pd_leftsourceformat_tl }, leftsourceformat .default:n = { }, leftsourceformat .initial:n = { },
% rightsourceformat .tl_set:c = { l_pd_rightsourceformat_tl }, rightsourceformat .default:n = { }, rightsourceformat .initial:n = { },
% boxrule .dim_set:c = { l_pd_boxrule_dim }, boxrule .default:n = { 0.2pt }, boxrule .initial:n = { 0.2pt },
% boxsep .dim_set:c = { l_pd_boxsep_dim }, boxsep .default:n = { 3pt }, boxsep .initial:n = { 3pt },
% leftquoteformat .tl_set:c = { l_pd_leftquoteformat_tl }, leftquoteformat .default:n = { }, leftquoteformat .initial:n = { },
% rightquoteformat .tl_set:c = { l_pd_rightquoteformat_tl }, rightquoteformat .default:n = { }, rightquoteformat .initial:n = { },
}

\tl_new:N \l_pd_thequote_tl %----------------------------- \cs_set:Npn \pd_funcqbox:nn #1#2 { \bool_if:cTF { l_pd_usephrasewidth_bool } { \tl_set:Nn \l_pd_thequote_tl { % \begin{tabular}{ccc} { \tl_use:c { l_pd_lqformat_tl } \tl_use:c { l_pd_lqmark_tl } } % &
{ % \begin{minipage}{0.82\linewidth} \tl_use:c { l_pd_leftquoteformat_tl }
{ #1 } \tl_use:c { l_pd_rightquoteformat_tl }
% \end{minipage} } % &
{ \tl_use:c { l_pd_rqformat_tl } \tl_use:c { l_pd_rqmark_tl } } % \ % \end{tabular}
} }%T bool { \tl_set:Nn \l_pd_thequote_tl { \begin{tabular}{ccc} { \tl_use:c { l_pd_lqformat_tl } \tl_use:c { l_pd_lqmark_tl } } &
{ \begin{minipage}{0.82\linewidth} \tl_use:c { l_pd_leftquoteformat_tl }
{ #1 } \tl_use:c { l_pd_rightquoteformat_tl }
\end{minipage} } &
{ \tl_use:c { l_pd_rqformat_tl } \tl_use:c { l_pd_rqmark_tl } } \ \end{tabular}
} }%F bool

            %--- inner
            \bool_if:cT
                        { l_pd_usephrasewidth_bool }
                        {
                            \tl_set:Nn 
                                    \l_tmpa_tl
                                    { 
                                            \tl_use:N 
                                                    \l_pd_thequote_tl
                                     }
                            \hbox_set:Nn 
                                    \l_tmpa_box
                                    { \l_tmpa_tl }
                            \dim_set:cn 
                                    { l_pd_innermpwidth_dim }
                                    {
                                        \box_wd:N \l_tmpa_box
                                    }
                        }
            %--- outer
            \bool_if:cT
                        { l_pd_usephraseouterwidth_bool }
                        {
                            \tl_set:Nn 
                                    \l_tmpa_tl
                                    { 
                                            \tl_use:N 
                                                    \l_pd_thequote_tl
                                     }
                            \hbox_set:Nn 
                                    \l_tmpa_box
                                    { \l_tmpa_tl }
                            \dim_set:cn 
                                    { l_pd_outermpwidth_dim }
                                    {
                                        \box_wd:N \l_tmpa_box
                                        + 4em
                                    }
                        }
            %===            
            \group_begin:

                    \setlength{\fboxrule}{ \dim_use:c { l_pd_boxrule_dim } }
                    \setlength{\fboxsep}{ \dim_use:c { l_pd_boxsep_dim } }

    \tl_use:c { l_pd_leftouterformat_tl }
                \fcolorbox
                            { \tl_use:c { l_pd_framecolour_tl } }
                            { \tl_use:c { l_pd_frameboxcolour_tl } }
                            {
            \begin{minipage}
                    { \dim_use:c { l_pd_outermpwidth_dim } }
                    \vspace{ \dim_use:c { l_pd_topmargin_dim } }
                    \tl_use:c { l_pd_leftinnerformat_tl }
                    \begin{minipage}
                                { \dim_use:c { l_pd_innermpwidth_dim } }
                                                                    \tl_use:N
                                                                                \l_pd_thequote_tl
                    \end{minipage}
                    \tl_use:c { l_pd_rightinnerformat_tl }

                                                \tl_use:c { l_pd_middlebreak_tl }

                                                        \tl_use:c { l_pd_leftsourceformat_tl }
                    {#2}
                   \tl_use:c { l_pd_rightsourceformat_tl } 

                    \vspace{ \dim_use:c { l_pd_bottommargin_dim } }
            \end{minipage}}
    \tl_use:c { l_pd_rightouterformat_tl }
    \group_end:

}

\NewDocumentCommand{\pdquotebox}{ o +m +m }{ %---

    \group_begin:
  \IfNoValueF { #1 }
{
    \keys_set:nn { pdqb } { #1 } 
    }

        \pd_funcqbox:nn { #2 } { #3 }
        \group_end:     

}

\ExplSyntaxOff

\begin{document}

\pdquotebox[ usephrasewidth=true, usephraseouterwidth=true, %middlebreak={\ \vspace{0pt}}, %rqformat={\color{red}}, %rqmark={ \ xxx }, %leftouterformat={\itshape\Large}, %rightouterformat={\upshape\normalsize}, leftinnerformat={\Large\itshape}, rightinnerformat={\upshape\normalsize}, leftsourceformat={\hfill\fnserif\bfseries\scshape\colorbox{yellow}}, leftquoteformat={\colorbox{red!5}}, boxrule={4pt}, frameboxcolour={green!32!yellow!10!red!2}, %outermpwidth={0.45\linewidth}, ]{Cogito ergo sum.}{Descartes}

\pdquotebox[innermpwidth={0.72\linewidth}]{Usually one approaches an optimization problem presupposing that $x^\star$ exists, is unique, and is located by the method to be used.}{R. Fletcher, \textit{Practical optimization methods}}

\pdquotebox[ usephrasewidth=true, leftsourceformat={\hfill}, leftquoteformat={\color{blue}}, leftinnerformat={}, framecolour={white}, ]{Cogito ergo sum.}{Descartes}

\end{document}

Cicada
  • 10,129