我使用的是等宽字体,并且希望所有行都水平对齐(“a” 应位于“a”正下方)。我该怎么做?
我注意到分页符也会移动文本。如何在 Tikz 中绘制最大宽度为一个字符的符号?
\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{mathabx}
\lstset{
breaklines=true,
frame=lines,
basicstyle=\ttfamily,
numbers=left,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\drsh\space}},
showlines=true
}
\begin{document}
\begin{lstlisting}
a = a a a a a a a a a a a a a a a a a a a a a a a ab a a a a a a a a a a a a a a a a a
\end{lstlisting}
\end{document}
答案1
您可以通过以下方式调整选项\raisebox
中数学的间距:postbreak
\mkern
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\mkern-12mu\drsh\mkern-4mu}},
平均能量损失
\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{mathabx}
\lstset{
breaklines=true,
frame=lines,
basicstyle=\ttfamily,
numbers=left,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\mkern-12mu\drsh\mkern-4mu}},
showlines=true
}
\begin{document}
\begin{lstlisting}
a = a a a a a a a a a a a a a a a a a a a a a a a ab a a a a a a a a a a a a a a a a a
\end{lstlisting}
\end{document}
输出
编辑
如果你需要这个符号\drsh
,但无法加载mathabx
到文档中,你可以简单地从包中“提取”符号的定义,并将其插入到文档中,即替换该行
\usepackage{mathabx}
和
\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
<5> <6> <7> <8> <9> <10> gen * mathb
<10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
}{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}
\DeclareMathSymbol{\drsh}{3}{mathb}{"EB}
MWE 产生与上面相同的输出:
\documentclass{article}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{listings}
%\usepackage{mathabx}
\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
<5> <6> <7> <8> <9> <10> gen * mathb
<10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
}{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}
\DeclareMathSymbol{\drsh}{3}{mathb}{"EB}
\lstset{
breaklines=true,
frame=lines,
basicstyle=\ttfamily,
numbers=left,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\mkern-12mu\drsh\mkern-4mu}},
showlines=true
}
\begin{document}
\begin{lstlisting}
a = a a a a a a a a a a a a a a a a a a a a a a a ab a a a a a a a a a a a a a a a a a
\end{lstlisting}
\end{document}