You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将tikzcd图与tikzpicture图并排垂直居中对齐?

解决subcaption子图垂直对齐异常的问题

你遇到的问题是因为subfigure的[t]选项对齐的是子图的基线,而非图形的顶部。默认情况下,TikZ图的基线位于图形底部,第一个tikzcd图整体高度远大于第二个坐标系图,两者基线对齐后,就出现了第一个图顶部和第二个图底部错位的视觉效果。

要实现垂直居中对齐,有两种简单可行的解决方法:


方法1:直接改用居中对齐选项

把两个subfigure的[t]替换为[c],这是最直接的实现方式:

\documentclass[a4paper,11pt]{report}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{cd}
%
\begin{document}
This is the first line
\begin{center}
\begin{figure}[h!tb]
\begin{subfigure}[c]{0.4\textwidth}
\centering
\begin{tikzcd}
R \ar[r,leftarrow,"f"] \ar[rd,leftarrow, "f\circ x^{-1}"']  &U \ar[r,leftarrow,"\gamma"] \ar[d,"x"] &R \ar[dl, "x \circ\gamma"]\\
& R^d
\end{tikzcd}
\end{subfigure}
\hfill % 用\hfill替代重复的\centering,让子图均匀分布
\begin{subfigure}[c]{0.4\textwidth}
\centering
\begin{tikzpicture}
\node at (1,1.4){$R^2$};
\draw[->] (0,0)node{$\bullet$}--(2,0)node[below]{$q^1$-axis};
\draw[->] (0,0)--(0,1.5)node[left]{$q^2$-axis};
\end{tikzpicture}
\end{subfigure}
\caption{This is a test}
\end{figure}
\end{center}
This is the last line.
\end{document}

方法2:调整TikZ图的基线(若坚持使用[t])

如果一定要保留[t]选项,可以给每个TikZ图设置基线到图形中心,让[t]对齐的是中心位置:

\documentclass[a4paper,11pt]{report}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{cd}
%
\begin{document}
This is the first line
\begin{center}
\begin{figure}[h!tb]
\begin{subfigure}[t]{0.4\textwidth}
\centering
% 给tikzcd设置基线到边界框中心
\begin{tikzcd}[baseline=(current bounding box.center)]
R \ar[r,leftarrow,"f"] \ar[rd,leftarrow, "f\circ x^{-1}"']  &U \ar[r,leftarrow,"\gamma"] \ar[d,"x"] &R \ar[dl, "x \circ\gamma"]\\
& R^d
\end{tikzcd}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.4\textwidth}
\centering
% 给普通tikzpicture设置基线到边界框中心
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node at (1,1.4){$R^2$};
\draw[->] (0,0)node{$\bullet$}--(2,0)node[below]{$q^1$-axis};
\draw[->] (0,0)--(0,1.5)node[left]{$q^2$-axis};
\end{tikzpicture}
\end{subfigure}
\caption{This is a test}
\end{figure}
\end{center}
This is the last line.
\end{document}

内容的提问来源于stack exchange,提问作者Jacques Smeets

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 06:36:21