如何將 tikzpicture 居中而不將包含它的 \item 居中?

如何將 tikzpicture 居中而不將包含它的 \item 居中?

我有一個特定的練習,我希望我創建的圖表tikzpicture居中,但我也希望\item包含它的標籤單獨保留,並與其級別的其他枚舉器保持一致。我已經成功地為我遇到的無數其他問題找到了解決方案(這是我的第一個 LaTeX 文件),但無論我嘗試過什麼答案,標籤\item(在本例中為 a (b))似乎被拉著去兜風,就像這樣:

![中心標籤項目napping

以下是我嘗試過的一些範例:

\begin{center}
  \begin{tikzpicture}
  ....
  \end{tikzpicture}
\end{center}

{\centering

  \begin{tikzpicture}
  ....
  \end{tikzpicture}

}

\begin{figure}
   \begin{center}
     \begin{tikzpicture}
      ....
     \end{tikzpicture}
   \end{center}
\end{figure}

\begin{tikzpicture}
  \centering

  ....
\end{tikzpicture}

....等等。我用前兩個得到了“最佳”結果,這對我來說似乎是相同的。 (b) 被拉到中心,且 ( tikzpictureb) 與其下方的文字之間沒有適當的垂直間距。但是,後續圖表(全部\item與第一個圖表相同)不存在此間距問題。對我來說\begin{center},引入一些本應超出其範圍的東西似乎很奇怪,但我確信有一個簡單的解釋。這是一個最小的工作範例(我打算重構它以最大程度地減少重複):

\documentclass[12pt]{article}

\usepackage[margin=1in]{geometry} 
\usepackage{amsmath,amsthm,amssymb,bm,enumitem,tikz}

\usetikzlibrary{calc,positioning,shapes}

\tikzset{
    between/.style args={#1 and #2}{
         at = ($(#1)!0.5!(#2)$)
    }
}

\tikzstyle{mydot}=[circle,fill,inner sep=2pt]
\tikzstyle{myellipse}=[ellipse,draw=cyan,thick,minimum width=60pt,minimum height=110pt,inner sep=0pt]
\tikzstyle{every edge}=[draw=cyan,thick]
\tikzstyle{relarrow}=[->, shorten >= 0pt, shorten <= 0pt, out=25, in=155]

\begin{document}

\begin{enumerate}
    \item
    \begin{enumerate}
        \item $R=\{(5,5),(6,5),(6,6)\}$,\\
              $S=\{(4,6),(5,5),(5,7),(6,6)\}$

        \item % Relation R
             \begin{center}
             \begin{tikzpicture}[
             >=latex,
             shorten >= 3pt,
             shorten <= 3pt,
             baseline={([yshift=-1em] current bounding box.north)}
             ]

             \node[mydot,label={left:4}] (a1) {}; 
             \node[mydot,below=of a1,label={left:5}] (a2) {}; 
             \node[mydot,below=of a2,label={left:6}] (a3) {}; 

             \node[mydot,right=5cm of a1,label={right:5}] (b1) {}; 
             \node[mydot,below=of b1,label={right:6}] (b2) {}; 
             \node[mydot,below=of b2,label={right:7}] (b3) {}; 

             \path[->] (a2) edge (b1);
             \path[->] (a3) edge (b1)
                 edge(b2);

             \node[myellipse,label={above:A}] at (a2.center) (c1) {};
             \node[myellipse,label={above:B}] at (b2.center) (c2) {};

             \node at (2.5, 0.75) (r1) {$R$};
             \path[relarrow] (2.1, 0.4) edge (2.95, 0.35);

             \end{tikzpicture}
             \end{center}

             $R$ is not a function because it fails both 
             properties (1) and (2) of the definition of a function.
             $4\in A$, but there is no $(4,y)\in R$ for any 
             $y\in B$.
             Also, \mbox{$(6,5)\in R$} and $(6,6)\in R\text{, but }
             5\neq6$.

             % Relation S
             \begin{center}
             \begin{tikzpicture}[
             >=latex,
             shorten >= 3pt,
             shorten <= 3pt,
             baseline={([yshift=-1em] current bounding box.north)}
             ]

             \node[mydot,label={left:4}] (a1) {}; 
             \node[mydot,below=of a1,label={left:5}] (a2) {}; 
             \node[mydot,below=of a2,label={left:6}] (a3) {}; 

             \node[mydot,right=5cm of a1,label={right:5}] (b1) {}; 
             \node[mydot,below=of b1,label={right:6}] (b2) {}; 
             \node[mydot,below=of b2,label={right:7}] (b3) {}; 

             \path[->] (a1) edge (b2);
             \path[->] (a2) edge (b1)
                 edge (b3);
             \path[->] (a3) edge (b2);

             \node[myellipse,label={above:A}] at (a2.center) (c1) {};
             \node[myellipse,label={above:B}] at (b2.center) (c2) {};

             \node at (2.5, 0.75) (r1) {$S$};
             \path[relarrow] (2.1, 0.4) edge (2.95, 0.35);

             \end{tikzpicture}
             \end{center}

             $S$ is not a function because it fails property 
             (2) of the definition of a function.
             $(5,5)\in S\text{ and }(5,7)\in S\text{, but }
             5\neq7$.

    \end{enumerate}
\end{enumerate}

\end{document}

答案1

我會考慮將此類圖表作為數學顯示,儘管添加一些介紹文字會更好。

\documentclass[12pt]{article}

\usepackage[margin=1in]{geometry} 
\usepackage{amsmath,amsthm,amssymb,bm,enumitem,tikz}

\usetikzlibrary{calc,positioning,shapes}

\tikzset{
  between/.style args={#1 and #2}{at = ($(#1)!0.5!(#2)$)},
  mydot/.style={circle,fill,inner sep=2pt},
  myellipse/.style={
    ellipse,
    draw=cyan,
    thick,
    minimum width=60pt,
    minimum height=110pt,
    inner sep=0pt
  },
  every edge/.style={draw=cyan,thick},
  relarrow/.style={->, shorten >= 0pt, shorten <= 0pt, out=25, in=155},
}

\begin{document}

\begin{enumerate}
\item
  \begin{enumerate}
  \item $R=\{(5,5),(6,5),(6,6)\}$,\\
        $S=\{(4,6),(5,5),(5,7),(6,6)\}$

  \item % Relation R
    \[
    \begin{tikzpicture}[
      >=latex,
      shorten >= 3pt,
      shorten <= 3pt,
      baseline={([yshift=-1em] current bounding box.north)}
    ]

    \node[mydot,label={left:4}] (a1) {}; 
    \node[mydot,below=of a1,label={left:5}] (a2) {}; 
    \node[mydot,below=of a2,label={left:6}] (a3) {}; 

    \node[mydot,right=5cm of a1,label={right:5}] (b1) {}; 
    \node[mydot,below=of b1,label={right:6}] (b2) {}; 
    \node[mydot,below=of b2,label={right:7}] (b3) {}; 

    \path[->] (a2) edge (b1);
    \path[->] (a3) edge (b1) edge(b2);

    \node[myellipse,label={above:$A$}] at (a2.center) (c1) {};
    \node[myellipse,label={above:$B$}] at (b2.center) (c2) {};

    \node at (2.5, 0.75) (r1) {$R$};
    \path[relarrow] (2.1, 0.4) edge (2.95, 0.35);

    \end{tikzpicture}
    \]
    $R$ is not a function because it fails both 
    properties (1) and (2) of the definition of a function.
    $4\in A$, but there is no $(4,y)\in R$ for any $y\in B$.
    Also, $(6,5)\in R$ and $(6,6)\in R$, but~$5\neq6$.

  \item % Relation S
    \[
    \begin{tikzpicture}[
      >=latex,
      shorten >= 3pt,
      shorten <= 3pt,
      baseline={([yshift=-1em] current bounding box.north)}
    ]

    \node[mydot,label={left:4}] (a1) {}; 
    \node[mydot,below=of a1,label={left:5}] (a2) {}; 
    \node[mydot,below=of a2,label={left:6}] (a3) {}; 

    \node[mydot,right=5cm of a1,label={right:5}] (b1) {}; 
    \node[mydot,below=of b1,label={right:6}] (b2) {}; 
    \node[mydot,below=of b2,label={right:7}] (b3) {}; 

    \path[->] (a1) edge (b2);
    \path[->] (a2) edge (b1) edge (b3);
    \path[->] (a3) edge (b2);

    \node[myellipse,label={above:$A$}] at (a2.center) (c1) {};
    \node[myellipse,label={above:$B$}] at (b2.center) (c2) {};

    \node at (2.5, 0.75) (r1) {$S$};
    \path[relarrow] (2.1, 0.4) edge (2.95, 0.35);

    \end{tikzpicture}
    \]
    $S$ is not a function because it fails property (2) of
    the definition of a function.
    $(5,5)\in S$ and $(5,7)\in S$, but~$5\neq7$.

  \end{enumerate}
\end{enumerate}

\end{document}

有幾點要注意:

  1. \tikzstyle已棄用

  2. 集合名稱應處於數學模式:label={above:$A$}適用於此

  3. 文字

    Also, \mbox{$(6,5)\in R$} and $(6,6)\in R\text{, but } 5\neq6$.
    

    應該

    Also, $(6,5)\in R$ and $(6,6)\in R$, but~$5\neq6$.
    
  4. 同樣,文本

    $(5,5)\in S\text{ and }(5,7)\in S\text{, but } 5\neq7$.
    

    應該

    $(5,5)\in S$ and $(5,7)\in S$, but~$5\neq7$.
    
  5. \]和後面的文字之間不要留空行。

在此輸入影像描述

答案2

您只需要添加\mbox{}或一些文字來攜帶項目標籤

在此輸入影像描述

\begin{document}

\begin{enumerate}
    \item
    \begin{enumerate}
        \item $R=\{(5,5),(6,5),(6,6)\}$,\\
              $S=\{(4,6),(5,5),(5,7),(6,6)\}$

        \item \mbox{}
             \begin{center}
             \begin{tikzpicture}[

答案3

像這樣:

在此輸入影像描述

解決方案相當簡單。之後\item只需b添加~\mbox{}。完整的 MWE 比(經過小改動)是:

\documentclass[12pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb,bm}
\usepackage{enumitem,tikz}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,shapes}

\tikzset{          >=latex,
           shorten >=3pt,
           shorten <=3pt,
between/.style args ={#1 and #2}{at = ($(#1)!0.5!(#2)$)},
      mydot/.style  ={circle,fill,inner sep=2pt},
  myellipse/.style  ={ellipse,draw=cyan,thick,
                      minimum width=60pt,minimum height=110pt,
                      inner sep=0pt},
 every edge/.style  ={draw=cyan,thick},
   relarrow/.style  ={->, out=25, in=155}
        }

\begin{document}

\begin{enumerate}
    \item
    \begin{enumerate}
        \item $R=\{(5,5),(6,5),(6,6)\}$,\\
              $S=\{(4,6),(5,5),(5,7),(6,6)\}$

        \item \mbox{}% <-- added      (Relation R  )
             \begin{center}
             \begin{tikzpicture}[
             baseline={([yshift=-1em] current bounding box.north)}
                                ]
             \node[mydot,label={left:4}] (a1) {};
             \node[mydot,below=of a1,label={left:5}] (a2) {};
             \node[mydot,below=of a2,label={left:6}] (a3) {};

             \node[mydot,right=5cm of a1,label={right:5}] (b1) {};
             \node[mydot,below=of b1,label={right:6}] (b2) {};
             \node[mydot,below=of b2,label={right:7}] (b3) {};

             \path[->] (a2) edge (b1);
             \path[->] (a3) edge (b1) edge (b2);

             \node[myellipse,label={above:A}] at (a2.center) (c1) {};
             \node[myellipse,label={above:B}] at (b2.center) (c2) {};

             \node at (2.5, 0.75) (r1) {$R$};
             \path[relarrow] (2.1, 0.4) edge (2.95, 0.35);
             \end{tikzpicture}
             \end{center}

     $R$ is not a function because it fails both properties (1) and (2) of the definition of a function. $4\in A$, but there is no $(4,y)\in R$ for any $y\in B$. Also, $(6,5)\in R$ and $(6,6)\in R$, but $5\neq6$.

             % Relation S
             \begin{center}
             \begin{tikzpicture}[
             baseline={([yshift=-1em] current bounding box.north)}
                                ]
             \node[mydot,label=left:4] (a1) {};
             \node[mydot,below=of a1,label=left:5] (a2) {};
             \node[mydot,below=of a2,label=left:6] (a3) {};

             \node[mydot,right=5cm of a1,label=right:5] (b1) {};
             \node[mydot,below=of b1,label=right:6] (b2) {};
             \node[mydot,below=of b2,label=right:7] (b3) {};

             \path[->] (a1) edge (b2);
             \path[->] (a2) edge (b1)
                 edge (b3);
             \path[->] (a3) edge (b2);

             \node[myellipse,label=above:A] at (a2.center) (c1) {};
             \node[myellipse,label=above:B] at (b2.center) (c2) {};

             \node at (2.5, 0.75) (r1) {$S$};
             \path[relarrow] (2.1, 0.4) edge (2.95, 0.35);
             \end{tikzpicture}
             \end{center}

             $S$ is not a function because it fails property (2) of the definition of a function. $(5,5)\in S$ and $(5,7)\in S$, but $5\neq7$.
    \end{enumerate}
\end{enumerate}
\end{document}

相關內容