我正在撰写我的硕士论文,需要呈现一些如下结构:
编辑:为了简化,示例不使用突出显示,但minted
如果可能的话,我想专门使用,而不仅仅是打字机字体。
目前,我正在使用array
环境,因为我需要居中、括号和嵌套。但是,它意味着数学模式,而我主要需要逐字逐句,所以我需要始终\mintinline{}{}
在每一行插入。
\[
\left[
\begin{array}{l}
\left[
\begin{array}{l}
\mintinline{text}{Note that} \\
\mintinline{text}{all text} \\
\mintinline{text}{is verbatim} \\
\end{array}
\right]
\to
\mintinline{text}{note vertical centering} \\[2em]
\left[
\begin{array}{l}
\mintinline{text}{Lorem ipsum} \\
\mintinline{text}{dolor sit amet, consectetur} \\
\end{array}
\right]
\to
\left[
\begin{array}{l}
\mintinline{text}{Note that} \\
\mintinline{text}{nested hierarchy} \\
\mintinline{text}{can be} \\
\mintinline{text}{quite complex} \\
\end{array}
\right] \\
\end{array}
\right]
\]
有没有什么方法可以让代码不那么丑陋和冗长?
此外,这不是必需的,但如果我可以通过箭头符号水平对齐每行,那就太好了。
我对 LaTeX 中的一些高级格式仍然缺乏经验,因此我将非常感谢任何帮助!
答案1
\documentclass{article}
\newcommand{\textarray}[1]{\ensuremath{\left[ \mbox{\ttfamily\begin{tabular}{l} #1 \end{tabular}}\right]}}
\begin{document}
\textarray{
\textarray{Note that \\ all text \\ is verbatim} $\rightarrow$ not vertical centering \\[4ex]
\textarray{Lorem ipsum \\ dolor sit amet, consectetur}
}
\end{document}
答案2
\documentclass{article}
\usepackage{verbatimbox,stackengine}
\setstackEOL{\\}
\begin{document}
\begin{myverbbox}{\UpLeft}
Note that
all text
is verbatim
\end{myverbbox}
\begin{myverbbox}{\UpRight}
note vertical centering
\end{myverbbox}
\begin{myverbbox}{\LowLeft}
Lorem ipsum
dolor sit amet, consecetur
\end{myverbbox}
\begin{myverbbox}{\LowRight}
Note that
nested hierarchy
can be
quite complex
\end{myverbbox}
\savestack\TopRow{$\bracketVectorstack{\UpLeft} \rightarrow \UpRight$}
\savestack\BottomRow{$\bracketVectorstack{\LowLeft} \rightarrow \bracketVectorstack{\LowRight}$}
\[
\renewcommand\stackalignment{l}
\left[
\stackanchor[8pt]{\TopRow}{\BottomRow}
\right]
\]
\end{document}
如果我花时间清理间距,并按照箭头对齐:
\documentclass{article}
\usepackage{verbatimbox,tabstackengine}
\TABstackMath
\begin{document}
\begin{myverbbox}{\UpLeft}
Note that
all text
is verbatim
\end{myverbbox}
\begin{myverbbox}{\UpRight}
note vertical centering
\end{myverbbox}
\begin{myverbbox}{\LowLeft}
Lorem ipsum \#@%$^&
dolor sit amet, consecetur
\end{myverbbox}
\begin{myverbbox}{\LowRight}
Note that
nested hierarchy
can be
quite complex
\end{myverbbox}
\savestack\TopRow{$\bracketVectorstack{\UpLeft}
\rightarrow \UpRight$}
\savestack\BottomRow{$\bracketVectorstack{\LowLeft}
\rightarrow \bracketVectorstack{\addstackgap{\LowRight}}$}
\[
\renewcommand\stackalignment{l}
\left[
\raisebox{6pt}{\tabbedstackanchor[8pt]{\bracketVectorstack{\UpLeft}
&\rightarrow \UpRight}{\bracketVectorstack{\LowLeft}
&\rightarrow \bracketVectorstack{\addstackgap{\LowRight}}}}
\right]
\]
\end{document}
答案3
无需输入:
\documentclass{article}
\usepackage{amsmath,mathtools,minted}
\newenvironment{lbmatrix}{\begin{bmatrix*}[l]}{\end{bmatrix*}}
\begin{document}
\[
\begin{lbmatrix}
\begin{lbmatrix}
\mintinline{text}{Note that} \\
\mintinline{text}{all text} \\
\mintinline{text}{is verbatim}
\end{lbmatrix}
\rightarrow
\mintinline{text}{note vertical centering}
\\[2ex]
\begin{lbmatrix}
\mintinline{text}{Lorem ipsum} \\
\mintinline{text}{dolor sit amet, consectetur}
\end{lbmatrix}
\rightarrow
\begin{lbmatrix}
\mintinline{text}{Note that} \\
\mintinline{text}{nested hierarchy} \\
\mintinline{text}{can be} \\
\mintinline{text}{quite complex}
\end{lbmatrix}
\end{lbmatrix}
\]
\end{document}