下面的代码我后面在提问的时候会多次提到,需要打补丁才能让源代码和格式化文本的框架都在文本宽度之内。
\documentclass{article}
\usepackage[showframe=false,a5paper,margin=1cm]{geometry}
\usepackage{showexpl,xcolor,caption}
\captionsetup
{
margin=5mm,
font={color=blue,rm,scriptsize},
labelfont={color=magenta,bf},
justification=justified,
labelsep=quad
}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\SX@codeInput}{xleftmargin=0pt,xrightmargin=0pt}{}
{\typeout{***Successfully patched \protect\SX@codeInput***}}
{\typeout{***ERROR! Failed to patch \protect\SX@codeInput***}}
\makeatother
\lstset
{
language={[LaTeX]TeX},
breaklines=true,
basicstyle=\scriptsize\ttfamily,
keywordstyle=\color{blue}\sffamily\bfseries,
backgroundcolor=\color{yellow!10},
frame=single,
rulecolor=\color{red},
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the following must be defined to make hacking work.
xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,
xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
vsep=2\fboxsep,
explpreset={}%must be called even if empty
}
\newcommand\dummy
{%
Anger is a condition in which the tongue works faster than the mind \ldots
}
\parindent=0pt
\begin{document}
\dummy
\begin{LTXexample}[caption=\dummy]
\dummy
\[E\not=mc^2\]
\end{LTXexample}
\dummy
\end{document}
问题
其余 3 个问题已被删除,只剩下以下问题来支持 Herbert 提供的答案。使用編輯歷史按钮查看原文。
在并排模式(pos=l
或pos=r
)下,如何将顶部框架与同一水平线对齐?
赫伯特的回答aboveskip=\dimexpr\fboxsep+\fboxrule\relax
将解答这个问题。
答案1
像你这样修补命令是没有意义的。但是,让两者对齐,在前言中插入:
\makeatletter
\renewcommand\SX@ResultArea[2]{%
\SX@justification\setlength\@tempdima{#1}%
\parbox[t]\@tempdima{\vspace{0pt}#2}}
\renewcommand\SX@CodeArea[2]{%
\setlength\@tempdima{#1}%
\sbox\@tempboxa{\parbox[t]\@tempdima{\vspace{0pt}#2}}%
\@tempdima=\dp\@tempboxa\usebox\@tempboxa
\rlap{\raisebox{-\@tempdima}[0pt][0pt]{\SX@attachfile}}}
\makeatother