
我想製作一個文字框,其中每一行都從同一列開始。但是,當我編譯文件時,由於某種原因,行沒有對齊。這是我的程式碼:
\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}