我想制作一个文本框,其中每行都从同一列开始。但是,当我编译文档时,由于某种原因,这些行没有对齐。这是我的代码:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\title{Example}
\lstset{basicstyle=\normalsize\ttfamily, breaklines=true}
\lstset{framextopmargin=10pt,framexbottommargin=10pt,frame=single}
\date{2012\\Julio}
\begin{document}
\maketitle
\noindent \textbf{\large{Example 1}}
\bigskip
\begin{lstlisting}
Example text. As you can see here, for some reason, and even though the first line of text is fine, the rest of the lines are not aligned
\end{lstlisting}
\end{document}
这是我编译时得到的结果:
我正在用 xetex 进行编译,我不知道这是否重要
答案1
当listings
换行太长时,它会在新行的开头插入一些空格。您可以通过设置来删除此breakindent=0pt
空格\lstset
:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\title{Example}
\lstset{
basicstyle=\normalsize\ttfamily,
breaklines=true,
framextopmargin=10pt,
framexbottommargin=10pt,
frame=single,
breakindent=0pt % <-- NEW
}
\date{2012\\Julio}
\begin{document}
\maketitle
\noindent \textbf{\large{Example 1}}
\bigskip
\begin{lstlisting}
Example text. As you can see here, for some reason, and even though the first line of text is fine, the rest of the lines are not aligned
\end{lstlisting}
\end{document}