pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.14k stars 108 forks source link

tikz nodes sometimes off center #418

Open pgf-tikz-bot opened 7 years ago

pgf-tikz-bot commented 7 years ago

Migrated from SourceForge Author: mistersheik Timestamp: 2017-02-09 00:41:44.473000

\documentclass[tikz]{standalone}
\usepackage{pgfcore}
\usepackage{pgfkeys}
\usetikzlibrary{
  positioning,
  circuits.ee,
  circuits.ee.IEC,
}
\begin{document}
\begin{tikzpicture}[circuit ee IEC,
                    set resistor graphic=var resistor IEC graphic,
                    set diode graphic=var diode IEC graphic,
                    set make contact graphic= var make contact IEC graphic]
  \node[voltage source] (s) {};
  \node[coordinate] (r) [right=30mm of s] {};
  \node[coordinate] (l) [right=20mm of r] {};
  \node[coordinate] (c) [right=20mm of l] {};
  \node (out) [right=10mm of c] {out};
  \node[ground] (g) [below=10mm of c, point down] {};
  \path
      (s) edge [resistor={info=R}] (r)
      (r) edge [inductor={info=L}] (l)
      (l) edge [capacitor={info=C}] (c)
      (c) edge (g)
      (c) edge (out);
\end{tikzpicture}
\end{document}
pgf-tikz-bot commented 5 years ago

Migrated from SourceForge Author: mo-gul Timestamp: 2018-12-27 15:25:19.850000

Diff:


--- old
+++ new
@@ -1,27 +1,27 @@
-\documentclass[tikz]{standalone}
-\usepackage{pgfcore}
-\usepackage{pgfkeys}
-\usetikzlibrary{
-  positioning,
-  circuits.ee,
-  circuits.ee.IEC,
-}
-\begin{document}
-\begin{tikzpicture}[circuit ee IEC,
-                    set resistor graphic=var resistor IEC graphic,
-                    set diode graphic=var diode IEC graphic,
-                    set make contact graphic= var make contact IEC graphic]
-  \node[voltage source] (s) {};
-  \node[coordinate] (r) [right=30mm of s] {};
-  \node[coordinate] (l) [right=20mm of r] {};
-  \node[coordinate] (c) [right=20mm of l] {};
-  \node (out) [right=10mm of c] {out};
-  \node[ground] (g) [below=10mm of c, point down] {};
-  \path
-      (s) edge [resistor={info=R}] (r)
-      (r) edge [inductor={info=L}] (l)
-      (l) edge [capacitor={info=C}] (c)
-      (c) edge (g)
-      (c) edge (out);
-\end{tikzpicture}
-\end{document}
+    \documentclass[tikz]{standalone}
+    \usepackage{pgfcore}
+    \usepackage{pgfkeys}
+    \usetikzlibrary{
+      positioning,
+      circuits.ee,
+      circuits.ee.IEC,
+    }
+    \begin{document}
+    \begin{tikzpicture}[circuit ee IEC,
+                        set resistor graphic=var resistor IEC graphic,
+                        set diode graphic=var diode IEC graphic,
+                        set make contact graphic= var make contact IEC graphic]
+      \node[voltage source] (s) {};
+      \node[coordinate] (r) [right=30mm of s] {};
+      \node[coordinate] (l) [right=20mm of r] {};
+      \node[coordinate] (c) [right=20mm of l] {};
+      \node (out) [right=10mm of c] {out};
+      \node[ground] (g) [below=10mm of c, point down] {};
+      \path
+          (s) edge [resistor={info=R}] (r)
+          (r) edge [inductor={info=L}] (l)
+          (l) edge [capacitor={info=C}] (c)
+          (c) edge (g)
+          (c) edge (out);
+    \end{tikzpicture}
+    \end{document}
muzimuzhi commented 3 years ago

This is caused by point down in \node[ground] (g) [below=10mm of c, point down] {};. point down is defined by point down/.style={rotate=-90} so the problem relates to node rotation.

The following tikz example reproduces the problem. This example is adopted from this TeX-SX Q&A which dates back to 2012 and contains various kinds of workarounds.

\documentclass[tikz, margin=5pt]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[nodes=draw]
  \node (a) {a};
  \foreach \i in {0,30,...,90} {
    \node[black!\i!cyan] (b\i) [right=10mm of a, rotate=\i] {a};
  }
\end{tikzpicture}
\end{document}

image

From the output, one can see the real problem is, the used rotation center is the node anchor set by placements options (here right=10mm of b), while the expected rotation center is the node center.

ilayn commented 3 years ago

This is not a problem but a shortcoming. You can't both anchor and rotate because otherwise 10mm will not be respected. An additional coordinate needs to be added here to separate the concerns

hmenke commented 3 years ago

I remember trying to fix this a couple of times (which is why it is milestoned) but was never able get anything consistent.

muzimuzhi commented 3 years ago

@hmenke Do you already have some test cases for this issue? When I am familiar enough with the node internals, I will have a try.

muzimuzhi commented 3 years ago

Perhaps a naive idea: add a new (node) macro storing the intended rotation center and a new flag representing whether the node anchor is indirectly changed by positioning options.