TeX - LaTeX Asked on May 7, 2021
Here’s a minimal tikz figure:
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
node [circle,draw] {A};
end{tikzpicture}
end{document}
That circle around the ‘A’ is bigger than I’d like. I want it to look more like this. (The ‘A’ is meant to be the same size as in the previous image, and the circle smaller.)
How can I achieve that? There are several previous questions about changing the size of a node, but they seem to be either about the size of an empty node, or making it bigger, which can be achieved with minimum size
or inner sep
. (I’m unsure about what these commands do or what the difference is, but they don’t seem to be what I want.) My goal is just to specify the radius of the node exactly, regardless of the size of its label.
The circle is a node in a graph, and should behave as a node of the correct size when connecting arrows to it and so on.
I guess I could just write a newcommand
to draw an empty node of the correct size and then write the label on top of it, but it feels like that’s not the intended way to use tikz, so I’m wondering what the proper way is.
Oh, well this was easier than I thought. One must combine the mysterious invocations inner sep
and minimum size
in the following manner:
documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
node [circle,draw, inner sep=0, minimum size=1.5em] {A};
end{tikzpicture}
end{document}
It looks weirdly off centre, but I'll live with that.
I imagine there's a reason why this works, and that it's written somewhere in the 1000 page manual. I wish I lived in a world in which I had time to read it.
Answered by Nathaniel on May 7, 2021
To obtain a perfect alignment whatever the letter used, you must set the height
and depth
of the text:
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}
tikzset{
circled node/.style={circle,draw, inner sep=0, minimum size=1.5em},
better circled node/.style={circled node,text height=.8em,text depth=.25em},
}
foreach letter[count=c] in {A,B,H,Q,Z,a,f,g,É}{
path (c*6mm, 0) node [circled node] (N-c) {letter};
path (c*6mm, -1) node [better circled node] (M-c) {letter};
}
draw[red,very thin,dashed] (N-1.base) -- ++(5cm,0);
draw[red,very thin,dashed] (M-1.base) -- ++(5cm,0);
end{tikzpicture}
end{document}
Answered by Paul Gaborit on May 7, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP