如何更改 LTXexample 的 rframe 的 \fboxsep 和 \fboxrule?

如何更改 LTXexample 的 rframe 的 \fboxsep 和 \fboxrule?

格式化的输出被 包围rframe。但在某些情况下, 的网格标签pspicture超出了框架。 的网格标签pspicture可能在 TeX 引擎之外渲染,因此 TeX 不知道它的确切尺寸。

简而言之,如何放大\fboxseprframe奖励:还请告诉我如何更改其\fboxrule

在此处输入图片描述

\documentclass{article}
\usepackage[paperwidth=13cm,paperheight=8cm,margin=0.5cm]{geometry}
\pagestyle{empty}
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}

\usepackage{xcolor}


\usepackage{showexpl}
\makeatletter

% Add [t] to the parbox
\renewcommand\SX@CodeArea[2]{%
   \parbox[t]{#1}{#2}
   \rlap{\parbox[t]{#1}{\SX@attachfile}}}

% Add [t] to the parbox
\renewcommand\SX@ResultArea[2]{%
  \SX@justification%
  \parbox[t]{#1}{#2}%
}

% Add \hbox{} at the creation of \SX@ResBox, look up the comment
\renewcommand*\SX@put@code@result{%
  \begingroup
    \expandafter\lstset\expandafter{\SX@explpreset}%
    \let\lst@float=\relax\let\SX@float=\relax
    \expandafter\lstset\expandafter{\SX@@explpreset}%
    \ifx\lst@float\relax\else
      \let\SX@float=\lst@float\let\lst@float=\relax
      \g@addto@macro\SX@@explpreset{,float=false}%
      \edef\@tempa{\noexpand\lst@beginfloat{lstlisting}[\SX@float]}%
      \expandafter\@tempa
    \fi
    \ifx\lst@caption\@empty
      \lstset{nolol=true}%
    \fi
    \if@SX@wide\def\SX@overhang{\marginparwidth+\marginparsep}\fi
    \trivlist\item\relax
      \stepcounter{ltxexample}\label{\SX@IDENT}%
      \SX@defaultWD\SX@width{\SX@width}%
      \ifdim\SX@width<\z@
        \@tempswatrue
        \def\@tempa{t}%
        \ifx\@tempa\SX@pos\@tempswafalse\fi
        \def\@tempa{b}%
        \ifx\@tempa\SX@pos\@tempswafalse\fi
        \setlength\@tempdima{\linewidth+\SX@overhang}%
        \if@tempswa\@tempdima=.5\@tempdima\fi%
        \edef\SX@width{\the\@tempdima}%
      \fi
      \ifx\SX@rframe\@empty
        \long\def\SX@frame##1{##1}%
      \else
        \let\SX@frame\fbox
        \setlength\@tempdima{\SX@width-2\fboxsep-2\fboxrule}%
        \edef\SX@width{\the\@tempdima}%
      \fi
      \isSX@odd{\def\@tempa{l}}{\def\@tempa{r}}%
      \makebox[\linewidth][\@tempa]{%
        \parbox{\linewidth+\SX@overhang}{%
          \let\@addtofilelist\@gobble
          \let\lst@ifdisplaystyle=\iftrue
          \SX@KillAboveCaptionskip\lst@MakeCaption{t}%
          \lst@belowskip=\z@
          \let\SX@MakeCaption\lst@MakeCaption
          \let\lst@MakeCaption\@gobble
          \setbox\SX@ResBox\vtop{\hbox{}\hbox{%    <---- HERE, modified line
            \SX@frame{%
              \@nameuse{\if@SX@varwidth varwidth\else minipage\fi}%
                \SX@width\relax\SX@resultInput%
                \@nameuse{end\if@SX@varwidth varwidth\else minipage\fi}}}}% <-- Also here, to close a brace
          \edef\SX@width{\the\wd\SX@ResBox}%
          \@ifundefined{SX@put@\SX@pos}%
            {\@latex@error{Parameter `\SX@pos' undefined}\@ehd}%
          {\@nameuse{SX@put@\SX@pos}%
            {\SX@width}{\box\SX@ResBox}{\SX@codeInput}}%
          \let\lst@MakeCaption\SX@MakeCaption
          \lst@MakeCaption{b}\SX@KillBelowCaptionskip
        }%
      }%
    \endtrivlist
    \ifx\SX@float\relax\else\expandafter\lst@endfloat\fi
    \gdef\SX@@explpreset{}%
  \endgroup
}
\makeatother

\lstset
{
    language={[LaTeX]TeX},
    alsolanguage={PSTricks},
    numbers=left,
    numbersep=1em,
    numberstyle=\tiny\color{red}\noaccsupp,
    frame=single,
    framesep=\fboxsep,
    framerule=\fboxrule,
    rulecolor=\color{red},
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
    breaklines=true,
    basicstyle=\scriptsize\ttfamily\null,% <--- Add \hbox{} here too
    keywordstyle=\color{blue},
    %identifierstyle=\color{magenta},
    commentstyle=\color[rgb]{0.13,0.54,0.13},
    backgroundcolor=\color{yellow!10},
    tabsize=2,
    columns=flexible,
    explpreset={pos=r,hsep=2\fboxsep,preset=\centering},
    morekeywords={
        graphicspath,
        includegraphics,
    },
    ,   
}

\usepackage{pstricks}

\begin{document}

\LTXexample
\begin{pspicture}[showgrid](5,5)

\end{pspicture}
\endLTXexample

\end{document}

例如,如果我们可以改变rframe\fboxsep=12pt我们可以得到如下输出:

在此处输入图片描述

答案1

一种不同的方法(我知道这并不完全符合要求并且不太优雅,但如果只需要做几次就可以使用)是放置在更大尺寸的内部\LTXexampleminipage容纳网格标签,并使用firstline,lastline键在输出中“隐藏”这些附加元素:

\documentclass{article}
\usepackage[paperwidth=13cm,paperheight=8cm,margin=0.5cm]{geometry}
\pagestyle{empty}
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}

\usepackage{xcolor}


\usepackage{showexpl}
\makeatletter

% Add [t] to the parbox
\renewcommand\SX@CodeArea[2]{%
   \parbox[t]{#1}{#2}
   \rlap{\parbox[t]{#1}{\SX@attachfile}}}

% Add [t] to the parbox
\renewcommand\SX@ResultArea[2]{%
  \SX@justification%
  \parbox[t]{#1}{#2}%
}

% Add \hbox{} at the creation of \SX@ResBox, look up the comment
\renewcommand*\SX@put@code@result{%
  \begingroup
    \expandafter\lstset\expandafter{\SX@explpreset}%
    \let\lst@float=\relax\let\SX@float=\relax
    \expandafter\lstset\expandafter{\SX@@explpreset}%
    \ifx\lst@float\relax\else
      \let\SX@float=\lst@float\let\lst@float=\relax
      \g@addto@macro\SX@@explpreset{,float=false}%
      \edef\@tempa{\noexpand\lst@beginfloat{lstlisting}[\SX@float]}%
      \expandafter\@tempa
    \fi
    \ifx\lst@caption\@empty
      \lstset{nolol=true}%
    \fi
    \if@SX@wide\def\SX@overhang{\marginparwidth+\marginparsep}\fi
    \trivlist\item\relax
      \stepcounter{ltxexample}\label{\SX@IDENT}%
      \SX@defaultWD\SX@width{\SX@width}%
      \ifdim\SX@width<\z@
        \@tempswatrue
        \def\@tempa{t}%
        \ifx\@tempa\SX@pos\@tempswafalse\fi
        \def\@tempa{b}%
        \ifx\@tempa\SX@pos\@tempswafalse\fi
        \setlength\@tempdima{\linewidth+\SX@overhang}%
        \if@tempswa\@tempdima=.5\@tempdima\fi%
        \edef\SX@width{\the\@tempdima}%
      \fi
      \ifx\SX@rframe\@empty
        \long\def\SX@frame##1{##1}%
      \else\setlength\fboxrule{1pt}
        \let\SX@frame\fbox
        \setlength\@tempdima{\SX@width-2\fboxsep-2\fboxrule}%
        \edef\SX@width{\the\@tempdima}%
      \fi
      \isSX@odd{\def\@tempa{l}}{\def\@tempa{r}}%
      \makebox[\linewidth][\@tempa]{%
        \parbox{\linewidth+\SX@overhang}{%
          \let\@addtofilelist\@gobble
          \let\lst@ifdisplaystyle=\iftrue
          \SX@KillAboveCaptionskip\lst@MakeCaption{t}%
          \lst@belowskip=\z@
          \let\SX@MakeCaption\lst@MakeCaption
          \let\lst@MakeCaption\@gobble
          \setbox\SX@ResBox\vtop{\hbox{}\hbox{%    <---- HERE, modified line
            \SX@frame{%
              \@nameuse{\if@SX@varwidth varwidth\else minipage\fi}%
                \SX@width\relax\SX@resultInput%
                \@nameuse{end\if@SX@varwidth varwidth\else minipage\fi}}}}% <-- Also here, to close a brace
          \edef\SX@width{\the\wd\SX@ResBox}%
          \@ifundefined{SX@put@\SX@pos}%
            {\@latex@error{Parameter `\SX@pos' undefined}\@ehd}%
          {\@nameuse{SX@put@\SX@pos}%
            {\SX@width}{\box\SX@ResBox}{\SX@codeInput}}%
          \let\lst@MakeCaption\SX@MakeCaption
          \lst@MakeCaption{b}\SX@KillBelowCaptionskip
        }%
      }%
    \endtrivlist
    \ifx\SX@float\relax\else\expandafter\lst@endfloat\fi
    \gdef\SX@@explpreset{}%
  \endgroup
}
\makeatother

\lstset
{
    language={[LaTeX]TeX},
    alsolanguage={PSTricks},
    numbers=left,
    numbersep=1em,
    numberstyle=\tiny\color{red}\noaccsupp,
    frame=single,
    framesep=\fboxsep,
    framerule=\fboxrule,
    rulecolor=\color{red},
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
    breaklines=true,
    basicstyle=\scriptsize\ttfamily\null,% <--- Add \hbox{} here too
    keywordstyle=\color{blue},
    %identifierstyle=\color{magenta},
    commentstyle=\color[rgb]{0.13,0.54,0.13},
    backgroundcolor=\color{yellow!10},
    tabsize=2,
    escapeinside={||},
    columns=flexible,
    explpreset={pos=r,hsep=2\fboxsep,preset=\centering},
    morekeywords={
        graphicspath,
        includegraphics,
    },
    ,   
}

\usepackage{pstricks}

\begin{document}

\LTXexample[firstline=3,lastline=5]
\begin{minipage}[c][5.8cm][c]{5.5cm}
\hfil
\begin{pspicture}[showgrid](5,5)

\end{pspicture}\hfil
\end{minipage}
\endLTXexample

\end{document}

在此处输入图片描述

相关内容