我有以下Latex
环境:
\newcounter{txtctr}[section] \setcounter{txtctr}{0}
\newenvironment{textex}{% This is the begin code
\refstepcounter{txtctr} \vspace{0.2cm} {\noindent
(T.\arabic{chapter}.\arabic{section}.\arabic{txtctr}):
}\footnotesize\vspace{-0.2cm}}{\normalsize}
但我希望在环境中的文本右侧和中间设置计数器。类似的东西:
Canis per flumen carnem dum ferret natans
aliamque praedam ab alio (T1.1.1)
Canis per flumen carnem dum ferret natans
我想这可能需要用minipage
来完成?顺便说一句,环境必须对verbatim
环境友好。
一些Latex向导能帮助我吗?
谢谢。
答案 0 :(得分:2)
我怀疑是否有自动执行此操作的程序包(即编号代码示例),但现在没有任何想法。
您正在使用哪个逐字包确切地说明了您想要如何执行此操作,但是像这样垂直居中的方框的一般技术是按照您的建议使用minipage。只需适当设置它们的宽度,就没有更多。
\begin{minipage}[c]{0.9\linewidth} % your environment goes here \end{minipage}\hfill \begin{minipage}[c]{0.09\linewidth} (T.\arabic{chapter}.\arabic{section}.\arabic{txtctr})% \end{minipage}
答案 1 :(得分:1)
尝试调整一下:
\documentclass{article}
\newcounter{txtctr}%Defines couter
\def\thetxtctr{\thesection-\arabic{txtctr}}%Typesets counter
\newenvironment{textex}{% This is the begin code
\begin{minipage}[c]{.8\textwidth}%
}%
{% This is ending code
\end{minipage}
\begin{minipage}[c]{.2\textwidth}
\flushright\thetxtctr
\end{minipage}
}
\begin{document}
\section{hhh}
\begin{textex}
\begin{verbatim}
Canis per flumen carnem dum ferret natans
aliamque praedam ab alio
Canis per flumen carnem dum ferret natans
\end{verbatim}
\end{textex}
\end{document}