3

I am using the following tikz-based command to create a circle around a letter.

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
        \node[shape=circle,draw,minimum size=4mm, inner sep=0pt] (char)
        {#1};}}

It works fine, but whenever I use multiple letters in the same line, they are not aligned.

circle not aligned

I guess it has something to do with the baseline, like the circle is created in reference to the center of mass. Notice that b and d are a bit higher than a and c. How could I fix that?

UPDATE

Following the advice I got from the comments (thank you all), I got the circles aligned to each other (which is what I wanted), but unfortunately not to the text:

alingment

I saw the other post proposing this propnode (the pink a), and I tried to shift it all over the place using the first argument, but it had no effect.

\pgfmathsetmacro{\nodebasesize}{1} % A node with a value of one will have this diameter
\pgfmathsetmacro{\nodeinnersep}{0.05}
\newcommand{\propnode}[5]{% position, name, options, value, label
\begin{tikzpicture}
    \pgfmathsetmacro{\minimalwidth}{sqrt(#4*\nodebasesize)}
    \node[#3,minimum width=\minimalwidth*1cm,inner sep=\nodeinnersep*1cm,circle,draw] (#2) at (#1) {#5};
    \end{tikzpicture}
}

In fact, propnode is a bit too high and circled is a bit too low. This is the code which calls everything:

(\circled{b},\circled{a},\circled{c},\circled{d},\propnode{0,4}{n05}{fill=pink,text=black}{0.15}{a}). 
  • Related: tex.stackexchange.com/q/7032/2552 – Jake May 3 '15 at 16:52
  • 1
    Change char.base to char.center. However note that in this case, the circles will be aligned but not the letters. Both is impossible (unless you make the circle bigger), because letters have different shapes unlike numbers (see the link Jake suggested). – Alenanno May 3 '15 at 17:02
  • 1
    They're aligned. But you need a strut to set the height and depth for each circle. That'll mean that the circles for a and c will be a bit bigger, which might not be desirable. – A.Ellett May 3 '15 at 17:40
2

Here's an example using a strut:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
        \node[shape=circle,draw,minimum size=4mm, inner sep=0pt] (char)
        {\rule[-3pt]{0pt}{\dimexpr2ex+2pt}#1};}}


\begin{document}

\foreach \myn [count=\myc] in {a,b,c,d,e,p,q}
{%%
  \circled{\myn}\ifnum\myc<7\relax,\fi
}%%

\end{document}

enter image description here

2

This is using an averaging algorithm:

\documentclass[]{article}\usepackage{amsmath,mathtools,amssymb,tikz}
\newlength\myheight
\newcommand*\ccircled[1]{\settowidth{\myheight}{#1}%
    \raisebox{-.1\myheight}{\tikz[baseline=(char.base)]{%
        \node[shape=circle,draw,minimum size=\myheight*\myheight*.4,inner sep=1pt](char){#1};}}}
\begin{document}
\ccircled{S}u\ccircled{z}u\ccircled{k}i
\end{document}

One can make it smoother depending how many squaring calculations one wants to do.

testing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.