1

MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes} 
\begin{document}

\begin{tikzpicture}

\tikzset{elips/.style={ellipse,draw},}
\tikzset{yuvar/.style={circle,draw},} % yuvar means circular in Turkish

\begin{scope}
    \node (A)[elips] at (0,0) {A}; % This should look like an ellipse but it doesn't
    \node (B)[yuvar] at (2,0) {B};
    \node (C)[elips] at (4,0) {AA}; % This is an ellipse but only if C's are doubled

\end{scope}

\end{tikzpicture}
\end{document}

In order to make the node A slightly elliptical (like a ball gently pressed from the top and bottom), I have to add more text to it, e.g. instead of putting just an A I have to put AA.

I have tried several things, such as tinkering with inner sep=0.5cm, etc but none of them worked it out.

How to make the node elliptical without having to add more than one letter or without considerably changing its default size?

Sample:

enter image description here

The a is flattened at the top and bottom, without considerably changing the size i.e. the horizontal length stays the same.

2
  • 1
    I guess inner xsep=2mm does that job. By looking through pgfmanual.pdf ctan.org/pkg/pgf, most of problems are solved ^^
    – Black Mild
    Commented May 19, 2022 at 12:00
  • Thank you for the comment. I've added a sample photo to describe the kind of ellipse I was aiming for. How to make that kind of ellipse? Update: I've browsed the PGF manual. Commented May 19, 2022 at 12:58

1 Answer 1

3

(Updated after comments and question edit)

When you use the ellipse shape, the ellipse will "fit tightly" the rectangle which encompasses the text and the inner separation. So, if you just want a slight difference, you can do the following (but notice that it does not apply to the last ellipse, which has to grow to fit the text):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}

\begin{tikzpicture}

\tikzset{elips/.style={ellipse,draw,minimum width=2em,minimum height=1.8em,inner ysep=0pt},}
\tikzset{yuvar/.style={circle,draw,minimum width=2em},} % yuvar means circular in Turkish

\begin{scope}
    \node (A)[elips] at (0,0) {A}; % This should look like an ellipse but it doesn't
    \node (B)[yuvar] at (1,0) {B};
    \node (C)[elips] at (2,0) {p};
    \node (D)[elips] at (3,0) {DD};
    \node (E)[elips] at (5,0) {EEEEEEE};
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

Notice that the difference between A and B is very similar to your sketch, but that will depend a lot on what is included in the circle. Descendant, like "p", will create asymmetries.

Another strategy is to use always an ellipse, but to force the text to a "fake" rectangle, like in the following code. The command \fixedsize (which can be surely optimized) will typeset the text centered on a fake rectangle of the given size, whichever the size of the text. Then you simply use an ellipse without inner sep:


\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{1pt}

\newcommand{\fixedsize}[3]{%width, height, content
    \parbox[c][#2][c]{#1}{\hfil\makebox[0pt][c]{#3}\hfil}%
}
\newcommand{\fitcircle}[1]{\fixedsize{1.2em}{1.2em}{#1}}
\newcommand{\fitoval}[1]{\fixedsize{1.2em}{1.0em}{#1}}

\begin{tikzpicture}
\tikzset{my/.style={ellipse,draw,inner sep=0pt}}
\begin{scope}
    \node (A)[my] at (0,0) {\fitcircle{A}};
    \node (B)[my] at (1,0) {\fitoval{B}};
    \node (C)[my] at (2,0) {\fitoval{p}};
    \node (D)[my] at (3,0) {\fitoval{DD}};
    \node (E)[my] at (5,0) {\fitoval{EEEEEEE}};
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

You can play with the sizes of \fitoval and \fitcircle to obtain what you need.

1
  • Thank you for the answer. However, that ellipse is seems to be considerably changed in size. I've just added a photo to describe the exact kind of ellipse I'd like to draw. There you might notice that the horizontal length of the ellipse stays the same as the default circular one but only it's shortened from top and bottom. How to make that kind of ellipse. Note that I've searched the other posts and browsed the PGF manual but there 's no information about this particular case. Commented May 19, 2022 at 13:02

You must log in to answer this question.

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