列表对齐问题

列表对齐问题

我有一个后续问题这个帖子 我正在使用 中的列表beamer。 中的内容listings被推得比幻灯片上的其他内容更靠左。 我正在使用下面的代码来纠正它,它工作正常。 但是,在列中,代码现在也向右移动,即使它在注释中完全对齐。 我该如何防止这种情况?

以下是一份简单的文档:

\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}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

答案1

这种向右移动是由于行首有额外的空格。可以通过添加[gobble=12]选项删除前 12 个空格来消除此问题,结果如下:

在此处输入图片描述

笔记:

  • 请注意,您的大部分前言都不需要说明问题。我在下面 MWE 中注释掉了其中几行。在发布 MWE 之前,应删除所有不会导致问题的软件包。

代码

\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}

相关内容