2

I am trying to use \newline in the columns environment but it doesn't seem to work. This is the minimum working code.

\documentclass{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\usefonttheme{serif}
\setbeamertemplate{frame numbering}[fraction]
\usepackage{tcolorbox}
\usepackage{xcolor}
\begin{document}
\begin{frame}
\frametitle{test}
\begin{columns}
\begin{column}{0.46\textwidth}
\begin{itemize}
\item bloop
\item foo
\end{itemize}
\end{column}
\begin{column}{0.65\textwidth}
    \begin{itemize}
        \item test
        \begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,hbox]
                \scriptsize\texttt{line1}
                \scriptsize\texttt{line2}
        \end{tcolorbox}
    \end{itemize}
\end{column}

\end{columns} \end{frame} \end{document}

I am trying to get "line1" and "line2" in two separate lines. Could you please give me a hint on how to achieve this. Thanks in advance.

  • Your issue is not related to the use of the columns environment but more related to the tcolorbox environment in which the two lines are placed. – leandriis Nov 01 '20 at 09:38
  • Is this specific to beamer class? Because I have used \newline in a latex article class and it worked fine for me. – prananna Nov 01 '20 at 09:43
  • No. This is not specific to the beamer documentclass beut definitely caused by the hbox option of your tcolorbox environment. Regarding the use of \newline: In a normal document there should almost nerver be the need to explicitly use \newline. – leandriis Nov 01 '20 at 09:48
  • 1
    unrelated but you have made your columns wider than \textwidth which may well make them fail to be projected if you present this – David Carlisle Nov 01 '20 at 10:14

1 Answers1

3

Here are two different possibilities:

enter image description here

enter image description here

\documentclass{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\usefonttheme{serif}
\setbeamertemplate{frame numbering}[fraction]
\usepackage{tcolorbox}
\usepackage{array}
\usepackage{xcolor}
\begin{document}
\begin{frame}
\frametitle{empty line between "line 1"  and "line 2" and without hbox}
\begin{columns}
\begin{column}{0.46\textwidth}
\begin{itemize}
\item bloop
\item foo
\end{itemize}
\end{column}
\begin{column}{0.65\textwidth}
    \begin{itemize}
        \item test
        \begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]
                \scriptsize\ttfamily line1
            line2
    \end{tcolorbox}
\end{itemize}

\end{column}

\end{columns} \end{frame}

\begin{frame} \frametitle{with hbox and a tabular environment} \begin{columns} \begin{column}{0.46\textwidth} \begin{itemize} \item bloop \item foo \end{itemize} \end{column} \begin{column}{0.65\textwidth} \begin{itemize} \item test \begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,hbox] \begin{tabular}{@{}>{\scriptsize\ttfamily}l@{}} line1 \
line2 \end{tabular} \end{tcolorbox} \end{itemize} \end{column}

\end{columns} \end{frame} \end{document}

leandriis
  • 62,593
  • Thank you for the awesome response. Could you point me to where I can read about the options you used in the tabular environment ? – prananna Nov 01 '20 at 09:41
  • 1
    @{} removes the small horizontal white space that is added between the start of a column and the start of the text inside of this column. See also clarification on the use of @{} with table headings?. >{...} can be used to insert come code that is added before every cell in this specific column. I added \scriptsize and \ttfamily here in order to avoid repeating \scriptsize\texttt{...} for both rows. Using >{...} needs the array package which I added to the preamble. – leandriis Nov 01 '20 at 09:44
  • Fantastic. Thank you. – prananna Nov 01 '20 at 09:52