3

How to I realize a dot (here just drawn as a circle) which stays the same size no matter how I scale the image.

Here is the example.

\begin{tikzpicture}[scale=1]
\draw[thick] (0,0)--(1,0);
\fill (0,0) circle (1pt);
\end{tikzpicture}

\begin{tikzpicture}[scale=3]
\draw[thick] (0,0)--(1,0);
\fill (0,0) circle (1pt);
\end{tikzpicture}

Probably I should use node instead of drawing another circle.

I used to use a node with ${\bullet}$ but this is not precisely centered and I cannot control the size.

edit The following works partially, but not for a not centered point:

\begin{tikzpicture}[scale=1]
\draw[thick] (0,0)--(1,0);
\fill[shift only] (0,0) circle (1pt);
\fill[shift only] (1,0) circle (1pt);
\end{tikzpicture}
\begin{tikzpicture}[scale=3]
\draw[thick] (0,0)--(1,0);
\fill[shift only] (0,0) circle (1pt);
\fill[shift only] (1,0) circle (1pt);
\end{tikzpicture}
\begin{tikzpicture}[scale=3]
\draw[thick] (0,0)--(1,0);
\fill[shift only] (0,0) circle (1pt);
\fill(1,0) {[shift only] circle (1pt)};
\end{tikzpicture}

Alternatively, how to draw a dot at a specific point having a fixed size w.r.t. to the line thickness, e.g. 1.5x as thick as a thick line.

2
  • which one is the wrong one and with negative scaling?
    – percusse
    Oct 27, 2014 at 22:35
  • the points should stay at the end points of the line is scaled...
    – Marcel
    Oct 27, 2014 at 22:36

4 Answers 4

5

You can reset the nontranslational scaling via shift only key. This will keep the translational part of the transformation but will set the matrix to identity. If you also want to cancel the current transformation you can use reset cm key.

\begin{tikzpicture}[scale=3]
\draw[thick] (0,0)--(1,0);
\fill[shift only] (0,0) circle (1pt);
\end{tikzpicture}

For the edit

\begin{tikzpicture}[xscale=-1,yscale=-0.3]
\draw[thick] (0.5,0.5)--(-0.2,-1);
\fill (0.5,0.5) circle[shift only,radius=1pt];
\fill (-0.2,-1) circle[shift only,radius=1pt];
\end{tikzpicture}

enter image description here

9
  • Very nice. Didn't know about this feature. Many thanks
    – moospit
    Oct 27, 2014 at 21:28
  • Wow... You are great. This feature is nice indeed.
    – enthu
    Oct 27, 2014 at 21:30
  • Still makes a problem because I also use xscale=-1 to reflect images.
    – Marcel
    Oct 27, 2014 at 22:03
  • @Marcel Change my example and it should be OK. Maybe your example is different in your actual case. I also feel like you are overusing scale keys.
    – percusse
    Oct 27, 2014 at 22:10
  • The problem is the point is not always in (0,0) ...
    – Marcel
    Oct 27, 2014 at 22:12
2

The solution is easy, move the scale code inside the path. Don't apply it to the whole tikz code:

Before:

enter image description here

After:

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes.geometric}
\begin{document}
    \begin{tikzpicture}[scale=1]
\draw[thick] (0,0)--(1,0);
\fill (0,0) circle (1pt);
\end{tikzpicture}

\begin{tikzpicture}
\draw[thick, scale=3] (0,0)--(1,0);
\fill (0,0) circle (1pt);
\end{tikzpicture}
\end{document}
3
  • This way around it would not help, but I can put the scale to the dot
    – Marcel
    Oct 27, 2014 at 21:15
  • @Marcel Yes, you may scale up the whole tikz box and then scale down the dot.
    – enthu
    Oct 27, 2014 at 21:17
  • Yes the point is I want the size relative to the line width and the overall scale is arbitrary, because I have a lot pictures which are more complicated like this.
    – Marcel
    Oct 27, 2014 at 21:21
1

Another way could be to do some math when setting the dot's size:

\documentclass[tikz, border=5mm]{standalone}

\newcommand{\myscale}{1}

\begin{document}
 \begin{tikzpicture}[scale=\myscale]
  \draw[thick] (0,0)--(1,0);
  \fill (0,0) circle (1pt/\myscale);
 \end{tikzpicture}

\renewcommand{\myscale}{3}

 \begin{tikzpicture}[scale=\myscale]
  \draw[thick] (0,0)--(1,0);
  \fill (0,0) circle (1pt/\myscale);
 \end{tikzpicture}
\end{document}

This way you can control, which elements should be (relative) scaled and which not.

For easier reuse of already written code you can use it this way:

\documentclass[tikz, border=5mm]{standalone}

\newcommand{\myimage}[2][1]{
 \begin{scope}[shift={#2}, scale=#1]
  \draw [thick] (0,0) -- (1,0);
  \fill (0,0) circle (1pt/#1);
 \end{scope}
}

\begin{document}
 \begin{tikzpicture}
  \myimage{(0,1)};
  \myimage[3]{(0,0)};
 \end{tikzpicture}
\end{document}
1
  • The point is I have a lot of images with dots on lines. I want to rescale them but the dots should stay the same relative to the line width. I have no idea of the scale because it is nested and too complicated...
    – Marcel
    Oct 27, 2014 at 21:29
0

I came up with a bit messy solution. Still not considering it elegant. It is a combination of the other solutions so far...

\documentclass[border=10]{standalone}
\usepackage{tikz}
\newcommand{\mydot}[1]{
 \begin{scope}[shift={#1}]
  \fill[shift only] (0,0) circle (1.3pt);
 \end{scope}}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[thick] (0,0)--(1,0);
\mydot{(0,0)};
\mydot{(1,0)};
\end{tikzpicture}
\begin{tikzpicture}[scale=3]
\draw[thick] (0,0)--(1,0);
\mydot{(0,0)};
\mydot{(1,0)};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .