10

I am preparing questionnaire template in LaTeX.

I have the following code (simplified):

\documentclass{article}
\begin{document}
\framebox{\parbox{4cm}{
    \textbf{3. How often do you have a headache?}\\
    \textit{(Choose one option)}\begin{flushright}
        never 0

        seldom 1

        often 2
    \end{flushright}            
}}
\end{document}

Output looks like this:

enter image description here

My questions are:

  • Why I get the blank lines(marked by red color on picture for convenience) before and after the flushright environment ?
  • How to remove them?
David Carlisle
  • 757,742
Yuriy Petrovskiy
  • 401
  • 6
  • 12

1 Answers1

9

\flushright and \flushleft are defined using \trivlist:

\def\flushright{\trivlist \raggedleft\item\relax}
\def\endflushleft{\endtrivlist}

and this adds some additional vertical space. If you don't want this additional space. you could use the \raggedleft, \raggedright commands instead of the \flushright, \flushleft environments. Another option would be to set \topset (and \parskip, and \partopset, if necessary) to 0pt:

\documentclass{article}
\begin{document}

\framebox{\parbox{4cm}{
    \textbf{3. How often do you have a headache?}\\
    \textit{(Choose one option)}\begin{flushright}
        never 0

        seldom 1

        often 2
    \end{flushright}            
}}

\framebox{\parbox{4cm}{\setlength\topsep{0pt}
    \textbf{3. How often do you have a headache?}\\
    \textit{(Choose one option)}\begin{flushright}
        never 0

        seldom 1

        often 2
    \end{flushright}            
}}


\framebox{\parbox{4cm}{
    \textbf{3. How often do you have a headache?}\\
    \textit{(Choose one option)}

\begingroup\raggedleft
        never 0

        seldom 1

        often 2\par
    \endgroup
}}

\end{document}

enter image description here

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128