我的主要目标是将标签放在 tikzfigures 的最左边。当我tikzfigure
在方程式内部定义时,它位于与标签碰撞的中心。由于右侧有空间,我如何将 tikzfigure 移到右侧以防止其与标签碰撞。请注意,我正在处理双列。
tex 代码(原始代码取自https://tex.stackexchange.com/a/661116/127048)
\documentclass[10pt,journal,compsoc]{IEEEtran} \usepackage{lipsum} \usepackage{amsmath} \makeatletter \newcommand{\leqnos}{\tagsleft@true\let\veqno\@@leqno} \newcommand{\reqnos}{\tagsleft@false\let\veqno\@@eqno} \reqnos \makeatother \usepackage{tikz-cd} \usetikzlibrary{positioning} \begin{document} \setcounter{page}{15} \begingroup\leqnos \lipsum[1][1-3] \begin{equation} \begin{tikzcd} B\times_A \end{tikzcd}~\tag{a} \end{equation} \begin{equation} \begin{tikzpicture}[baseline=(current bounding box.center),compute/.style={draw,thick,font=\sffamily, append after command={ (\tikzlastnode.south west) edge[double=gray!50,double distance=3pt, line cap=rect, shorten >=-2pt,shorten <=-2pt] (\tikzlastnode.south east)}}] \node[compute] (n1) {Node}; \node[compute,right=2cm of n1, yshift=11mm] (n2) {More text}; \node[compute,right=2.2cm of n2] (n3) {More}; \node[compute,below=2cm of n2] (n4) {text}; \draw[thick,-stealth] (n1) -- (n2) -- (n3) -- (n4); \end{tikzpicture}~\tag{b} \end{equation} \endgroup \end{document}
输出:
这里如果 tikz 图形向右移动,它与标签的碰撞就会被阻止。
答案1
您的图片太宽,无法容纳在一列宽度内。在这种情况下,图片必须放在一列中,旁边是
- 将字体大小缩小至
\small
甚至\footnotesie
至 - 通过允许在节点中输入多行文本来减少节点的宽度,
- 减少模式之间的水平距离,
能做什么的可能性不大。上述如何实现的一个例子是:
\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{lipsum}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\usepackage{amsmath}
\makeatletter
\newcommand{\leqnos}{\tagsleft@true\let\veqno\@@leqno}
\newcommand{\reqnos}{\tagsleft@false\let\veqno\@@eqno}
\reqnos
\makeatother
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,
positioning}
\begin{document}
\lipsum[1][1-3]
\begingroup\leqnos
\begin{equation}
\begin{tikzcd}
B\times_A
\end{tikzcd}~\tag{a}
\end{equation}
\begin{equation}
\begin{tikzpicture}[baseline=(current bounding box.center),
node distance = 13mm,
compute/.style = {draw, thick, font=\small\sffamily, align=center,
append after command={\pgfextra{\let\LN\tikzlastnode}
(\LN.south west) edge[double=gray!50,double distance=3pt,
line cap=rect,
shorten >=-2pt,shorten <=-2pt]
(\LN.south east)}},
]
\node[compute] (n1) {Node};
\node[compute,right=of n1] (n2) {More text};
\node[compute,right=of n2] (n3) {More text text\\ text text text};
\node[compute,below=of n2] (n4) {text};
\draw[thick,draw, -Stealth, shorten > = 3pt, shorten < = 3pt]
(n1) edge (n2)
(n2) edge (n3)
(n3) to (n4);
\end{tikzpicture}~\tag{b}
\end{equation}
\endgroup
\lipsum
\end{document}
附录: 来自评论如下:
- 在你的方法中不可能得到你想要的
- 一种方法是定义新环境,其左侧有(不可引用)标签,右侧有图像或其他文本,居中或左侧不规则。
- sucn 命令的示例可以是:
\usepackage{tabularray}
\newcommand\LST[3]{
\begin{center}
\begin{tblr}{colspec={@{} Q[c, font=\bfseries] X[#1] @{}} }
#2 & #3
\end{tblr}
\end{center}}
- 在使用上述定义时你需要稍微重新定义
compute
节点样式:
compute/.style = {draw, thick, font=\small\sffamily, align=center,
append after command={\pgfextra{\let\LN\tikzlastnode}
([xshift=-2pt] \LN.south west)
edge[double=gray!50,double distance=3pt,
line cap=rect]
([xshift=+2pt] \LN.south east)}},
]
- 上述如何使用的示例如下:
\documentclass[journal,compsoc]{IEEEtran}
\usepackage{tabularray}
\newcommand\LST[3]{
\begin{center}
\begin{tblr}{colspec={@{} Q[c, font=\bfseries] X[#1] @{}} }
#2 & #3
\end{tblr}
\end{center}}
\usepackage{caption}
\usepackage[export]{adjustbox}
\usepackage[label font=bf, labelformat=simple]{subfig}
\usepackage{lipsum}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,
positioning}
\begin{document}
\lipsum[1][1-3]
\LST{c}{(a)}{$B\times_A$}
\LST{r}{(b)}{%
\begin{tikzpicture}[baseline=(current bounding box.center),
node distance = 12mm,
compute/.style = {draw, thick, font=\small\sffamily, align=center,
append after command={\pgfextra{\let\LN\tikzlastnode}
([xshift=-2pt] \LN.south west)
edge[double=gray!50,double distance=3pt,
line cap=rect]
([xshift=+2pt] \LN.south east)}},
]
\node[compute] (n1) {Node};
\node[compute,right=of n1] (n2) {More text};
\node[compute,right=of n2] (n3) {More text text\\ text text text};
\node[compute,below=of n2] (n4) {text};
\draw[thick,draw, -Stealth, shorten > = 3pt, shorten < = 3pt]
(n1) edge (n2)
(n2) edge (n3)
(n3) to (n4);
\end{tikzpicture}%
}
\lipsum
\end{document}
抱歉,由于(github)服务器错误,我无法上传使用上述 MWE 生成的图像。