Text FormattingVertical alignment in multicols environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
nikolaik
Posts: 2
Joined: Sun May 30, 2010 11:17 am

Vertical alignment in multicols environment

Post by nikolaik »

Hi all

in this example:

Code: Select all

\documentclass[12pt]{article}
\pagestyle{empty}

\usepackage{multicol}
\usepackage[neverdecrease]{paralist}

\begin{document}
\begin{multicols}{3}
\begin{enumerate}[a)]
\item%
\setlength{\unitlength}{1cm}
\begin{picture}(0,0) 
\linethickness{1pt} 
\put(-1,0){\line(1,0){16}} 
\end{picture}  
$\displaystyle z (x; y) = x - y $ 
\item% 
$\displaystyle z (x; y) = \frac{x}{y}$
\item%
$\displaystyle z (x; y) = x + y$  
\end{enumerate}
\end{multicols}
\end{document}
the item b) is lower than the items a) and c).
The picture (line) is added to show these differences.
How can this be corrected?

Thanks in advance

Nikolai
Last edited by nikolaik on Sun May 30, 2010 8:18 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Vertical alignment in multicols environment

Post by localghost »

I can comprehend the problem with your MWE. Seems to be caused by the different height of the second item so the multicol package runs into trouble. I suggest to use the inparaenum environment from the paralist package.

Code: Select all

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[neverdecrease]{paralist}

\pagestyle{empty}

\begin{document}
  \begin{inparaenum}[a)]
    \item $\displaystyle z(x;y)=x-y$\qquad
    \item $\displaystyle z(x;y)=\frac{x}{y}$\qquad
    \item $\displaystyle z(x;y)=x+y$
  \end{inparaenum}
\end{document}
As you can see you have to add some horizontal space but finally you got a proper vertical alignment. Another idea could be to "hide" the height of the fraction to make the compiler neglect it.

Code: Select all

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage[neverdecrease]{paralist}

\pagestyle{empty}

\begin{document}
  \begin{multicols}{3}
    \begin{enumerate}[a)]
      \item $\displaystyle z(x;y)=x-y$
      \item $\displaystyle z(x;y)=\smash{\frac{x}{y}}$
      \item $\displaystyle z(x;y)=x+y$
    \end{enumerate}
  \end{multicols}
\end{document}
This aligns the items vertically in a proper way.


Best regards and welcome to the board
Thorsten
nikolaik
Posts: 2
Joined: Sun May 30, 2010 11:17 am

Vertical alignment in multicols environment

Post by nikolaik »

Thank you!

The second solution is working for me.
I put every item completely into \smash:

Code: Select all

\begin{enumerate}[a)]
  \item $\displaystyle \smash{z(x;y)=x-y}$
  \item $\displaystyle \smash{z(x;y)=\frac{x}{y}}$
  \item $\displaystyle \smash{z(x;y)=x+y}$
\end{enumerate}
Never used \smash before.

Kind regards,

Nikolai
Post Reply