Wie kann ich ein Tikz-Bild zentrieren, ohne das \item, das es enthält, zu zentrieren?

Wie kann ich ein Tikz-Bild zentrieren, ohne das \item, das es enthält, zu zentrieren?

Ich habe eine spezielle Übung, bei der ich ein Diagramm, das ich mit erstellt habe, tikzpicturezentrieren möchte, aber ich möchte auch, dass die Beschriftung für das \item, das es enthält, unverändert bleibt und mit den anderen Enumeratoren auf seiner Ebene übereinstimmt. Ich habe erfolgreich Lösungen für die unzähligen anderen Probleme gefunden, die ich hatte (dies ist mein erstes LaTeX-Dokument), aber egal, welche Antwort ich ausprobiert habe, die \itemBeschriftung (in diesem Fall a (b)) scheint mitgeschleift zu werden, wie hier:

![center tag itemnapping

Hier sind einige Beispiele meiner Versuche:

\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}

... und so weiter. Die „besten“ Ergebnisse erziele ich mit den ersten beiden, die mir identisch erscheinen. Das (b) wird in die Mitte gezogen, und es gibt keinen richtigen vertikalen Abstand zwischen dem tikzpictureund dem Text darunter. Nachfolgende Diagramme (die alle unter demselben \itemwie das erste stehen) haben dieses Abstandsproblem jedoch nicht. Es erscheint mir bizarr, dass \begin{center}etwas hineingezogen wird, das eigentlich außerhalb seines Geltungsbereichs liegen sollte, aber ich bin sicher, dass es eine einfache Erklärung gibt. Hier ist ein (ziemlich) minimales funktionierendes Beispiel (ich beabsichtige, es umzugestalten, um die Wiederholung zu minimieren):

\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}

Antwort1

Ich würde solche Diagramme als mathematische Darstellungen betrachten, obwohl es besser wäre, einen einführenden Text hinzuzufügen.

\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}

Einige Hinweise:

  1. \tikzstyleist veraltet

  2. Die Setnamen sollten im Mathemodus sein: label={above:$A$}funktioniert für diese

  3. Der Text

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

    sollte sein

    Also, $(6,5)\in R$ and $(6,6)\in R$, but~$5\neq6$.
    
  4. Ebenso der Text

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

    sollte sein

    $(5,5)\in S$ and $(5,7)\in S$, but~$5\neq7$.
    
  5. \]Lassen Sie zwischen und dem folgenden Text keine Leerzeile .

Bildbeschreibung hier eingeben

Antwort2

Sie müssen nur \mbox{}etwas Text hinzufügen, um das Artikeletikett zu tragen

Bildbeschreibung hier eingeben

\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}[

Antwort3

So was:

Bildbeschreibung hier eingeben

Die Lösung ist ziemlich einfach. Fügen Sie nach \itemfor beinfach ~oder hinzu \mbox{}. Das vollständige MWE lautet dann (nach kleinen Änderungen):

\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}

verwandte Informationen