我有一个 tikz-cd 图,对于页面来说有点太宽了。默认情况下,当放置在 displaymath 环境中时,它会溢出到右侧边距。我希望它位于页面中央,溢出到两个边距(每个边距一半)。我知道的最好的方法是将整个图表放在 mathclap 中。但这会破坏 & 符号,要求ampersand replacement
使用除普通 之外的其他符号来提供和编写tikz-cd &
。我怎样才能编写普通的 tikz-cd 图并将其置于页面中央,而无需将所有&
s 替换为\&
(或其他)?
下面是产生我想要的结果的 MWE:
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\[
\mathclap{\begin{tikzcd}[ampersand replacement=\&]
\text{Lorem ipsum dolor sit amet} \ar[r] \&
\text{consectetur adipiscing elit} \ar[r] \&
\text{sed do eiusmod tempor incididunt}
\end{tikzcd}}
\]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{document}
我希望能够写如下内容:
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\begin{centeredtikzcd}
\text{Lorem ipsum dolor sit amet} \ar[r] &
\text{consectetur adipiscing elit} \ar[r] &
\text{sed do eiusmod tempor incididunt}
\end{centeredtikzcd}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{document}
答案1
使用以下方法定义您自己的环境lrbox
:
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\newenvironment{forcedcentertikzcd}
{\begin{lrbox}{\forcedcentertikzcdbox}\begin{tikzcd}}
{\end{tikzcd}\end{lrbox}\makebox[0pt]{\usebox{\forcedcentertikzcdbox}}}
\newsavebox{\forcedcentertikzcdbox}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
\[
\begin{forcedcentertikzcd}
\text{Lorem ipsum dolor sit amet} \ar[r] &
\text{consectetur adipiscing elit} \ar[r] &
\text{sed do eiusmod tempor incididunt}
\end{forcedcentertikzcd}
\]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
\end{document}
答案2
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\[
\hspace{-.2\textwidth}\begin{tikzcd}
\text{Lorem ipsum dolor sit amet} \ar[r] &
\text{consectetur adipiscing elit} \ar[r] &
\text{sed do eiusmod tempor incididunt}
\end{tikzcd}\hspace{-.2\textwidth}
\]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{document}