如果 tikzfigure 在方程式內部,如何將 tikzfigure 對齊到最右邊?

如果 tikzfigure 在方程式內部,如何將 tikzfigure 對齊到最右邊?

我的主要目標是在 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 圖形向右移動,將防止其與標籤發生碰撞。

有關的:如何在多個 tikz 圖形的最左邊顯示 (a) (b) 標誌?

答案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 產生的映像。

答案2

我猜您希望“標籤 (b)”和流程圖之間有更多空間。但我對你的 MWE 沒有任何問題。也許只是因為頁邊距設定?請參閱下面附件: 在此輸入影像描述

如果我猜錯了,請評論並詳細說明您想要什麼。

相關內容