3

Say I want the description environment in

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Some text\\
some more
\begin{center}
center
\end{center}
\begin{description}
  \item[desc1] text1
  \item[desc2] text2 text2
  \item[desc3] text3 text3 text3
\end{description}
other text
\end{document}

do be horizontally centered, as a whole, i.e. the longest item should be horizontally centered in the page. Clearly, if one of the entries is longer than \textwidth, then it would be back the original position.

Enclosing it in the center environment doesn't seem to work.

I thought \hfill would come handy, but I haven't managed to write a solution using it.

I guess another strategy could consist in computing the width of the environment being typeset, and using that as the width of an enclosing minipage, or something.


I see here using tabular as an alternative is proposed, but I was looking for a cleaner solution.

3
  • 1
    Hi, can you please post a compilable snippet? And specify what you mean by "horizontally centered": each line on its own? The whole block? What if any line is longer than the line width?
    – Rmano
    May 8 at 9:45
  • 1
    @Rmano, better now?
    – Enlico
    May 8 at 9:57
  • Much better now, thanks. The problem with center is that description generate full lines... thinking about it.
    – Rmano
    May 8 at 10:09

1 Answer 1

4

You can put the description in a varwidth-box (which produces a minpage and calculates it's width):

\documentclass{article}

\usepackage{amsmath}
\usepackage{varwidth}

\begin{document}
Some text\\
some more
\begin{center}
center
\end{center}

\begin{center}
  \begin{varwidth}{\textwidth}
    \begin{description}
      \item[desc1] text1
      \item[desc2] text2 text2
      \item[desc3] text3 text3 text3
    \end{description}
  \end{varwidth}
\end{center}

other text
\end{document}

enter image description here

2
  • I'd say perfect. I'll wait a bit more before accepting, in order to see another answer that probably Rmano is gonna add. +1 in the meanwhile
    – Enlico
    May 8 at 12:03
  • 2
    @Enlico no, I won't add anything, this is a very nice answer!
    – Rmano
    May 8 at 13:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .