![所有文档的垂直对齐](https://linux22.com/image/246461/%E6%89%80%E6%9C%89%E6%96%87%E6%A1%A3%E7%9A%84%E5%9E%82%E7%9B%B4%E5%AF%B9%E9%BD%90.png)
我正在处理文本,这是我的数学包的规范。规范的典型样式如下:
我只能在单个环境中使用align
或array
等对齐表达式。但我希望,所呈现图像中的所有示例都将根据\to
符号对齐通过所有文件。有啥办法吗?
所呈现图像的代码(抱歉,它相当复杂):
\documentclass[a4paper,titlepage,11pt,oneside]{book}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{latexsym}
\usepackage{array}
\usepackage{xargs}
\usepackage{xparse}
\usepackage{xcolor}
\usepackage{empheq}
\usepackage{courier}
\newcommand{\mkey}[1]{{\mbox{\small\ttfamily #1}}}
\newcommand{\mobj}[2]{\mbox{\ttfamily\small #1}\left [\,#2\,\right]}
\definecolor{boxcolor}{rgb}{.95, .95, 1}
\newsavebox{\mysaveboxM} % M for math
\newcommand*\MetaBox[2][Example]{%
\sbox{\mysaveboxM}{#2}%
\sbox{\mysaveboxM}{%
\parbox[b][\ht\mysaveboxM][b]{%
\wd\mysaveboxM}{#2}%
}%
\sbox{\mysaveboxM}{%
\fcolorbox{black}{boxcolor}{%
\makebox[\linewidth-4em]{\usebox{\mysaveboxM}}%
}%
}%
\usebox{\mysaveboxM}%
}
\NewDocumentEnvironment{meta}{O{equation*}O{}}{%
\setkeys{EmphEqEnv}{#1}%
\setkeys{EmphEqOpt}{box=\MetaBox,#2}%
\EmphEqMainEnv}%
{\endEmphEqMainEnv}
\begin{document}
\subsection{Product}
....
\subsubsection{Indices}
\begin{meta}
\begin{array}{rcl}
\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.indices}&\to&
\mobj{UnorderedIndices}{{}^{kj}{}_{jk}{}^{\mu}{}_{qa}}
\end{array}
\end{meta}
The interesting point introduced here is a special type of product
indices. We will discuss it in section. The general idea here is that
from the mathematical point of view the order of resulting product indices
is undefined.
\subsubsection{List access operations}
\begin{meta}
\begin{array}{rcl}
\mobj{}{V_{\alpha\beta}M_\sigma
Ric^{\kappa\delta}\,\delta^\alpha{}_{\kappa}}\mkey{.size()}&\to&4\\[12pt]
\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.elements}&\to&
\mobj{List}{H^{kj},\,M_j,\,Q_k{}^{\mu}{}_{qa}}
\end{array}
\end{meta}
One of the important (and really hard) decisions we've made is to
consider only commutative theories. So, while processing products, the order
of elements is not taken into account! However, there are some tricks to
work with non-commutative theories.\newline Indeed, you can take an element
by index:
\begin{meta}
\begin{array}{rcl}
\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.get(2)}&\to&
\mobj{SimpleTensor}{Q_k{}^\mu{}_{qa}}
\end{array}
\end{meta}
\end{document}
答案1
另一种方法是使用\makebox[<size>][l|r|c]{<text>}
将左侧和右侧都设置到一个大小完全相同的框中,并将箭头放在\to
中间。这里我假设您希望左侧的r
ight 对齐,右侧的l
eft 对齐:
笔记:
根据评论中的要求,您可以调整
\MetaHShift
控制线条向右移动的程度。因此,此处的负值将向左移动。此处的零值将导致箭头\to
位于中心。不
array
应该要求使用 。但empheq
现在允许我像第二个示例一样添加新行,因此array
仅将结构用于此目的。可能有一种方法可以添加新行,而无需使用array
。另请注意,array
选项用于@{}
消除左右两侧的列间距。在我看来,
ensuremath
在中使用\makebox
可以提高可读性,但$...$
也可以使用。
代码:
\documentclass[a4paper,titlepage,11pt,oneside]{book}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{latexsym}
\usepackage{array}
\usepackage{xargs}
\usepackage{xparse}
\usepackage{xcolor}
\usepackage{empheq}
\usepackage{courier}
\newcommand{\mkey}[1]{{\mbox{\small\ttfamily #1}}}
\newcommand{\mobj}[2]{\mbox{\ttfamily\small #1}\left [\,#2\,\right]}
\definecolor{boxcolor}{rgb}{.95, .95, 1}
\newsavebox{\mysaveboxM} % M for math
\newcommand*\MetaBox[2][Example]{%
\sbox{\mysaveboxM}{#2}%
\sbox{\mysaveboxM}{%
\parbox[b][\ht\mysaveboxM][b]{%
\wd\mysaveboxM}{#2}%
}%
\sbox{\mysaveboxM}{%
\fcolorbox{black}{boxcolor}{%
\makebox[\linewidth-4em]{\usebox{\mysaveboxM}}%
}%
}%
\usebox{\mysaveboxM}%
}
\NewDocumentEnvironment{meta}{O{equation*}O{}}{%
\setkeys{EmphEqEnv}{#1}%
\setkeys{EmphEqOpt}{box=\MetaBox,#2}%
\EmphEqMainEnv%
}{%
\endEmphEqMainEnv%
}
%%
\newcommand*{\MetaHShift}{-0.5em}
\newlength{\widthOfArrow}%
\newlength{\widthOfLeftText}%
\newlength{\widthOfRightText}%
\settowidth{\widthOfArrow}{${}\to{}$}%
\newcommand*{\CentredArrow}[2]{%
\setlength{\widthOfLeftText}{\dimexpr0.5\linewidth-0.5\widthOfArrow+\MetaHShift\relax}%
\setlength{\widthOfRightText}{\dimexpr0.5\linewidth-0.5\widthOfArrow-\MetaHShift\relax}%
\makebox[\widthOfLeftText][r]{\ensuremath{#1}}%
\ensuremath{{}\to{}}%
\makebox[\widthOfRightText][l]{\ensuremath{#1}}%
}%
\begin{document}
\subsection{Product}
....
\subsubsection{Indices}
\begin{meta}
\begin{array}{@{}l@{}}
\CentredArrow{\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.indices}}
{\mobj{UnorderedIndices}{{}^{kj}{}_{jk}{}^{\mu}{}_{qa}}}
\end{array}
\end{meta}
The interesting point introduced here is a special type of product
indices. We will discuss it in section. The general idea here is that
from the mathematical point of view the order of resulting product indices
is undefined.
\subsubsection{List access operations}
\begin{meta}
\begin{array}{@{}l@{}}
\CentredArrow{\mobj{}{V_{\alpha\beta}M_\sigma
Ric^{\kappa\delta}\,\delta^\alpha{}_{\kappa}}\mkey{.size()}}{4}
\\[12pt]
\CentredArrow{\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.elements}}{
\mobj{List}{H^{kj},\,M_j,\,Q_k{}^{\mu}{}_{qa}}}
\end{array}
\end{meta}
One of the important (and really hard) decisions we've made is to
consider only commutative theories. So, while processing products, the order
of elements is not taken into account! However, there are some tricks to
work with non-commutative theories.\newline Indeed, you can take an element
by index:
\begin{meta}
\begin{array}{@{}l@{}}
\CentredArrow{\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.get(2)}}{
\mobj{SimpleTensor}{Q_k{}^\mu{}_{qa}}}
\end{array}
\end{meta}
\end{document}
答案2
此解决方案使用 TikZ 找到符号的位置,然后从边界框中切除符号的左侧部分。然后,指定将\symbolOffset
符号从左边距移动多远。偏移量将是整个文档的(前提是\symbolOffset
未在某处设置为新值)。由于环境meta
会自动将其内容居中,因此数组被包裹以minipage
再次获得左对齐(否则偏移量不起作用)。文件必须需要编译两次才能正常工作。
这个解决方案的缺点是您必须手动调整偏移量,以免任何部分溢出。
我已将我的解决方案纳入您的示例中:
\documentclass[a4paper,titlepage,11pt,oneside]{book}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{latexsym}
\usepackage{array}
\usepackage{xargs}
\usepackage{xparse}
\usepackage{xcolor}
\usepackage{empheq}
\usepackage{courier}
\newcommand{\mkey}[1]{{\mbox{\small\ttfamily #1}}}
\newcommand{\mobj}[2]{\mbox{\ttfamily\small #1}\left [\,#2\,\right]}
\definecolor{boxcolor}{rgb}{.95, .95, 1}
\newsavebox{\mysaveboxM} % M for math
\newcommand*\MetaBox[2][Example]{%
\sbox{\mysaveboxM}{#2}%
\sbox{\mysaveboxM}{%
\parbox[b][\ht\mysaveboxM][b]{%
\wd\mysaveboxM}{#2}%
}%
\sbox{\mysaveboxM}{%
\fcolorbox{black}{boxcolor}{%
\makebox[\linewidth-4em]{\usebox{\mysaveboxM}}%
}%
}%
\usebox{\mysaveboxM}%
}
\NewDocumentEnvironment{meta}{O{equation*}O{}}{%
\setkeys{EmphEqEnv}{#1}%
\setkeys{EmphEqOpt}{box=\MetaBox,#2}%
\EmphEqMainEnv}%
{\endEmphEqMainEnv}
% --- NEW STUFF --------------------
\usepackage{tikz}
\usetikzlibrary{calc}
\newlength{\symbolOffset}
\setlength{\symbolOffset}{6.2cm} % Distance between the left margin and the
% symbol
\newcommand{\thesymbol}{$\to$} % Symbol
\newcommand{\alignSymbol}{%
\begin{tikzpicture}%
\node [inner sep=0pt] (symbol) {\thesymbol};
\end{tikzpicture}%
}
\newcommand{\alignArray}[1]{%
\begin{minipage}{\textwidth}%
\hspace*{\symbolOffset}%
\begin{tikzpicture}[remember picture]%
\node (array) [inner sep=0pt] {${#1}$};
\pgfresetboundingbox
\path [use as bounding box]
(symbol |- array.north) rectangle (array.south east);
\end{tikzpicture}%
\end{minipage}%
}
% --- END NEW STUFF ----------------
\begin{document}
\subsection{Product}
....
\subsubsection{Indices}
\begin{meta}
\alignArray{
\begin{array}{rcl}
\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.indices}&\alignSymbol&
\mobj{UnorderedIndices}{{}^{kj}{}_{jk}{}^{\mu}{}_{qa}}
\end{array}
}
\end{meta}
The interesting point introduced here is a special type of product indices. We
will discuss it in section. The general idea here is that from the mathematical
point of view the order of resulting product indices is undefined.
\subsubsection{List access operations}
\begin{meta}
\alignArray{
\begin{array}{rcl}
\mobj{}{V_{\alpha\beta}M_\sigma
Ric^{\kappa\delta}\,\delta^\alpha{}_{\kappa}}\mkey{.size()}&\alignSymbol&4\\[12pt]
\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.elements}&\alignSymbol&
\mobj{List}{H^{kj},\,M_j,\,Q_k{}^{\mu}{}_{qa}}
\end{array}
}
\end{meta}
One of the important (and really hard) decisions we've made is to consider only
commutative theories. So, while processing products, the order of elements is
not taken into account! However, there are some tricks to work with
non-commutative theories.\newline Indeed, you can take an element by index:
\begin{meta}
\alignArray{
\begin{array}{rcl}
\mobj{}{H^{kj}M_jQ_k{}^{\mu}{}_{qa}}\mkey{.get(2)}&\alignSymbol&
\mobj{SimpleTensor}{Q_k{}^\mu{}_{qa}}
\end{array}
}
\end{meta}
\end{document}