9

In the following LaTeX Beamer MWE, why is the spacing of the itemization so bad and why can it be fixed by adding a percentage sign after (... subitems)?

Most importantly: is there a reliable and elegant way to prevent this bad spacing in my presentations?

(I know that percentage signs somehow prevent parsing of line endings, but even starting the subitemization directly after (...subitems) doesn't have the same effect.)

\documentclass{beamer}
\begin{document}
    \begin{frame}
    \begin{columns}
        \begin{column}{0.5\textwidth}   
                \begin{itemize}         
                    \item A. (requires three sub-items)
                    \begin{itemize}
                        \item A.1
                        \item A.2
                        \item A.3
                    \end{itemize}
                    \item B
                \end{itemize}
        \end{column}
    \end{columns}
\end{frame}
\end{document}

Without percentage sign

\documentclass{beamer}
\begin{document}
    \begin{frame}
    \begin{columns}
        \begin{column}{0.5\textwidth}   
                \begin{itemize}         
                    \item A. (requires three sub-items)%
                    \begin{itemize}
                        \item A.1
                        \item A.2
                        \item A.3
                    \end{itemize}
                    \item B
                \end{itemize}
        \end{column}
    \end{columns}
\end{frame}
\end{document}

with percentage sign

Bananach
  • 627
  • 1
    The problem is that the linebreak without % is like inserting a space. In your example this is exactly at the width of the columns, so the additional space gets pushed to the next line – samcarter_is_at_topanswers.xyz Nov 28 '18 at 09:41
  • @samcarter is there a nicer way to avoid this in my presentations than by routinely always adding this percentage sign before subitemizations? The MWE looks cooked up, but it is the result of a long boiling down of a real example in which this bit me – Bananach Nov 28 '18 at 09:43
  • @samcarter I just edited this question into my original question – Bananach Nov 28 '18 at 09:45
  • @samcarter I just understood that the percentage sign has no special function here and the problem can even occur with it – Bananach Nov 28 '18 at 09:46
  • 2
    The % has a special function here, it prevents the insertion of an additional space – samcarter_is_at_topanswers.xyz Nov 28 '18 at 09:48
  • "Is there a nicer way to avoid this in my presentations than by routinely always adding this percentage sign before subitemizations?" This would be the clean way. In reality is is very unlikely that the end of your line is exactly at the end of the available textwidth, thus I would just keep in mind that this can happen and insert % signs when you notice this problem – samcarter_is_at_topanswers.xyz Nov 28 '18 at 09:49

2 Answers2

10

The definition of itemize in beamer is buggy. The problem is that is sets a color before the list, and color commands inserts whatsits and this has the effect that the space suddenly matters. beamer should at least add an \unskip before the color:

\documentclass{beamer}
\makeatletter

\renewcommand{\itemize}[1][]{%
  \ifhmode\unskip\fi %<<< or \unskip \par
  \ifblank{#1}{}{\def\beamer@defaultospec{#1}}%
  \ifnum \@itemdepth >2\relax\@toodeep\else
    \advance\@itemdepth\@ne
    \beamer@computepref\@itemdepth% sets \beameritemnestingprefix
    \usebeamerfont{itemize/enumerate \beameritemnestingprefix body}%
    \usebeamercolor[fg]{itemize/enumerate \beameritemnestingprefix body}% problem
    \usebeamertemplate{itemize/enumerate \beameritemnestingprefix body begin}%
    \list
      {\usebeamertemplate{itemize \beameritemnestingprefix item}}
      {\def\makelabel##1{%
          {%
            \hss\llap{{%
                \usebeamerfont*{itemize \beameritemnestingprefix item}%
                \usebeamercolor[fg]{itemize \beameritemnestingprefix item}##1}}%
          }%
        }%
      }
  \fi%
  \beamer@cramped%
  \raggedright%
  \beamer@firstlineitemizeunskip%
}

\begin{document}
    \begin{frame}
        \begin{minipage}{0.5\textwidth}
                \begin{itemize}
                    \item A. (requires three sub-items)                   
                    \begin{itemize}
                        \item A.1
                        \item A.2
                        \item A.3
                    \end{itemize}
                    \item B
                \end{itemize}
        \end{minipage}
\end{frame}
\end{document}
Ulrike Fischer
  • 327,261
6

Thanks, I found another reason for not relying on indentation but rather on spacing out the input. ;-)

Yes, itemize in beamer has a small bug, but it becomes irrelevant if you type in like the left column below.

\documentclass{beamer}
\begin{document}

\begin{frame}

\begin{columns}
\begin{column}{0.5\textwidth}   

\begin{itemize} 
\item A. (requires three sub-items)

\begin{itemize}
\item A.1
\item A.2
\item A.3
\end{itemize}

\item B

\end{itemize}
\end{column}

\begin{column}{0.5\textwidth}   

\begin{itemize} 
\item A. (requires three sub-items)
\begin{itemize}
\item A.1
\item A.2
\item A.3
\end{itemize}

\item B

\end{itemize}
\end{column}

\end{columns}

\end{frame}

\end{document}

enter image description here

egreg
  • 1,121,712