Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a follow up question to this post I am using listings in beamer. The content in listings is being pushed further left than the other contents on my slides. I am using the code below to correct for it and it works fine. However, within columns the code is now also shifted to the right even though it was perfectly aligned within a comment. How can I prevent this?

Here is a minimalist document:

\documentclass{beamer}

\usepackage{remreset}
\usepackage{comment} % end and begin comment
\usepackage{dtklogos} % for \BibTeX



\usepackage{graphicx} % importing figure
\usepackage{caption}
\usepackage{subcaption}

\usepackage{verbatim} % writing code 

\usepackage[english]{babel}

\makeatletter
\@removefromreset{subsection}{section} % creates navigation circles for every slide not section
\makeatother
\setcounter{subsection}{1} % creates navigation circles for every slide not section

\usepackage{listings} % display code on slides; don't forget [fragile] option after \begin{frame}
\usepackage{bera} % font for code in slides
\usepackage{color}
\definecolor{lightgrey}{rgb}{0.92,0.92,0.92} % defining color for listing
\definecolor{darkgreen}{rgb}{0,0.6,0} % defining color for listing

\lstset{language=[LaTeX]TeX,
basicstyle=\small\ttfamily,
texcsstyle=*\bf\color{blue},
numbers=left,
numberstyle=\scriptsize\color{gray},
breaklines=true,
keywordstyle=\color{darkgreen},
commentstyle=\color{red},
morekeywords={},
otherkeywords={$,\{ ,\} , [ , ], & },
frame=leftline,
tabsize=2,
backgroundcolor=\color{lightgrey},
escapeinside=<>,
moretexcs={maketitle, subsection, subsubsection, appendix, tableofcontents,
includegraphics},
}

\usepackage{calc}
\newlength\listingnumberwidth
\setlength\listingnumberwidth{\widthof{00} + 1em}
\lstset{
numbers=left,
xleftmargin=\listingnumberwidth,
numbersep=1em
}

% move text box
 \setbeamersize{text margin left=0.5cm}
 \setbeamersize{text margin right=0.5cm}

\usetheme{Frankfurt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%****************************************************
\begin{frame}[fragile]
\frametitle{Tables}
\framesubtitle{The Body}

\begin{enumerate}
\begin{columns}[t]
    \begin{column}{3.5cm}
        \item The Preamble
        \begin{lstlisting}
            \documentclass{}
            ...
            \usepackage{}
            ...         
            \title{}
            \author{}
            \date{}
        \end{lstlisting}
    \end{column}

    \begin{column}{6.5cm}
        \item The Body
        \begin{lstlisting}
            \begin{document}
            \maketitle

            % Body of document

            \end{document}
        \end{lstlisting}
    \end{column}
\end{columns}
\end{enumerate}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
share|improve this question

1 Answer 1

This shifting to the right is due the additional blank space at the beginning of the line. This can be removed by adding [gobble=12] option to delete the first 12 spaces to yield:

enter image description here

Notes:

  • Note that much of your preamble was not require to illustrate the problem. I commented out a few of these line the MWE below. Any packages that do not contribute the problem should be removed before posting the MWE.

Code

\documentclass{beamer}

\usepackage{remreset}
%\usepackage{comment} % end and begin comment
%\usepackage{dtklogos} % for \BibTeX



%\usepackage{graphicx} % importing figure
%\usepackage{caption}
%\usepackage{subcaption}

%\usepackage{verbatim} % writing code 

\usepackage[english]{babel}

%\makeatletter
%\@removefromreset{subsection}{section} % creates navigation circles for every slide not section
%\makeatother
%\setcounter{subsection}{1} % creates navigation circles for every slide not section

\usepackage{listings} % display code on slides; don't forget [fragile] option after \begin{frame}
\usepackage{bera} % font for code in slides
\usepackage{color}
\definecolor{lightgrey}{rgb}{0.92,0.92,0.92} % defining color for listing
\definecolor{darkgreen}{rgb}{0,0.6,0} % defining color for listing

\lstset{language=[LaTeX]TeX,
basicstyle=\small\ttfamily,
texcsstyle=*\bf\color{blue},
numbers=left,
numberstyle=\scriptsize\color{gray},
breaklines=true,
keywordstyle=\color{darkgreen},
commentstyle=\color{red},
morekeywords={},
otherkeywords={$,\{ ,\} , [ , ], & },
frame=leftline,
tabsize=2,
backgroundcolor=\color{lightgrey},
escapeinside=<>,
moretexcs={maketitle, subsection, subsubsection, appendix, tableofcontents,
includegraphics},
}

\usepackage{calc}
\newlength\listingnumberwidth
\setlength\listingnumberwidth{\widthof{00} + 1em}
\lstset{
numbers=left,
xleftmargin=\listingnumberwidth,
numbersep=1em
}

% move text box
 \setbeamersize{text margin left=0.5cm}
 \setbeamersize{text margin right=0.5cm}

\usetheme{Frankfurt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%****************************************************
\begin{frame}[fragile]
\frametitle{Tables}
\framesubtitle{The Body}

\begin{enumerate}
\begin{columns}[t]
    \begin{column}{3.5cm}
        \item The Preamble
        \begin{lstlisting}[gobble=12]
            \documentclass{}
            ...
            \usepackage{}
            ...         
            \title{}
            \author{}
            \date{}
        \end{lstlisting}
    \end{column}

    \begin{column}{6.5cm}
        \item The Body
        \begin{lstlisting}[gobble=12]
            \begin{document}
            \maketitle

            % Body of document

            \end{document}
        \end{lstlisting}
    \end{column}
\end{columns}
\end{enumerate}

\end{frame}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.