Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a set of numbers with some decorations (circled or rounded) using tikz or pifont package. The issue is they look ugly because they don't look like aligned. Is there way to align (or move) them vertically to look better?

\documentclass{article}

\usepackage{tikz}
\usepackage{pifont}

\newcommand{\round}[1]{%
  \tikz[baseline=(char.base)]\node[anchor=south west, draw,rectangle, rounded corners, inner sep=1pt, minimum size=3mm,
    text height=2mm](char){\ensuremath{#1}} ;}

\let\oldding\ding% Store old \ding in \oldding
\renewcommand{\ding}[2][1]{\scalebox{#1}{\oldding{#2}}}
\newcommand{\circled}[1]{\ding[1.2]{\numexpr171 + #1}}

\begin{document}

1\round{2,4}\circled{3}5\circled{6}\circled{7}\circled{8}

\end{document}

enter image description here

share|improve this question
    
these look ugly in different ways. the numeral(s) should, in my opinion, be aligned to the baseline, with the enclosure appearing to be "added afterward". for the case of the digits encircled by \round, the baseline is good, but the appearance is bad because the top is too tightly enclosed; addition of a strut or \vphantom (may have to experiment with height) would help. –  barbara beeton Aug 27 '13 at 13:03
    
What do you want to change? The pifont characters (which is not really possible without creating the glyphs from scratch apart from lowering the box itself). For a de-uglisation of the TikZ solution, you might try to explain the choices you made (text width, inner sep, etc). –  Qrrbrbirlbel Aug 27 '13 at 13:06

3 Answers 3

up vote 6 down vote accepted

I’d use for both (single digit vs multiple digits) the same setup so that the font and the outline are the same. TikZ provides the rounded rectangle shape in the shapes.misc library.

The great depth that the , adds is ignored by setting a specific text depth. This looks good in combination with the normal height of a digit. If this is going to be used for other stuff it might be good to add text height=\heightof{0} or font=\vphantom{0}.

Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\tikzset{
  every round node/.style={
    draw,
    shape=rounded rectangle,
    rounded rectangle arc length=180,
    inner sep=+.333em,
    text depth=+.1ex},
  light/.style={fill=none, text=black},
  dark/.style={fill=black, text=white}}
\newcommand{\round}[2][]{%
  \tikz[baseline]
    \node[
      every round node,
      anchor=base,
      #1]{$#2$};}
\begin{document}

1\round{2,4}\round{3}5\round{6}\round[fill=blue, text=green]{7}\round{8}

{\tikzset{every round node/.append style={dark}}
1\round{2,4}\round{3}5\round{6}\round{7}\round[text=red]{8}}

1\round{2,4}\round{3}5\round{6}\round{7}\round{8}
\end{document}

Output

enter image description here

share|improve this answer
    
+1, shame I thought I was going to get a tikz tick, but now I suspect not:( –  David Carlisle Aug 27 '13 at 13:54

You are using different fonts depending on the decoration shape, which is always going to look strange. As you are using tikz for the compound, you need to use it for the simple circle decoration as well:

enter image description here

\documentclass{article}

\usepackage{tikz}
\usepackage{pifont}

\newcommand{\round}[1]{%
  \tikz[baseline=(char.base)]\node[anchor=south west, draw,rectangle, rounded corners, inner sep=2pt](char){\ensuremath{#1}} ;}

\newcommand{\circled}[1]{%
  \tikz[baseline=(char.base)]\node[anchor=south west, draw,circle, inner sep=1pt,](char){\ensuremath{#1}} ;}



\begin{document}

1\round{2,4}\circled{3}5\circled{6}\circled{7}\circled{8}

\end{document}
share|improve this answer
    
I use pifont as it provides darkened circle: tex.stackexchange.com/questions/130239/…. Any way to do the same thing with tikz? –  prosseek Aug 27 '13 at 13:18
2  
@prosseek Just add fill=black, text=white as an option to the node. –  Qrrbrbirlbel Aug 27 '13 at 13:22
    
It seems like there's excessive white space in the bottom of the box for the 2 and the 3. I know it's caused by the comma pushing the depth. It there a nice clean way to handle this short of putting the comma in a box with smaller depth? –  A.Ellett Aug 27 '13 at 13:25
    
@A.Ellett yes I wondered if I should ignore the depth of the contents (which looks better here) but don't know in general what the contents might be,,, –  David Carlisle Aug 27 '13 at 13:42
    
@Qrrbrbirlbel thanks, my tikz knowledge is limited to guessing that changing rectangle, rounded corners to circle would make a circle:-) –  David Carlisle Aug 27 '13 at 13:44

You can use a \raisebox in your definition of \circled to get:

\documentclass{article}

\usepackage{tikz}
\usepackage{pifont}

\newcommand{\round}[1]{%
  \tikz[baseline=(char.base)]\node[anchor=south west, draw,rectangle, rounded corners, inner sep=1pt, minimum size=3mm,
    text height=2mm](char){\ensuremath{#1}} ;}

\let\oldding\ding% Store old \ding in \oldding
\renewcommand{\ding}[2][1]{\scalebox{#1}{\oldding{#2}}}
%\newcommand{\circled}[1]{\ding[1.2]{\numexpr171 + #1}}
\newcommand{\circled}[1]{\raisebox{-1.5pt}{\ding[1.2]{\numexpr171 + #1}}}

\begin{document}

1\round{2,4}\circled{3}5\circled{6}\circled{7}\circled{8}

\end{document}

enter image description here

In this way, the baselines of the digits can be vertically aligned.

However, in order to avoid a change of font, you could do this:

\documentclass{article}

\usepackage{tikz}
\usepackage{pifont}

\newcommand{\round}[1]{%
  \tikz[baseline=(char.base)]\node[anchor=south west, draw,rectangle,
    rounded corners, inner sep=1pt, minimum size=3mm,
    text height=2.5mm](char){\ensuremath{\,#1\,}} ;}

\let\oldding\ding% Store old \ding in \oldding
\renewcommand{\ding}[2][1]{\scalebox{#1}{\oldding{#2}}}
%\newcommand{\circled}[1]{\ding[1.2]{\numexpr171 + #1}}
\newcommand{\circled}[1]{\round{\!#1\!}}

\begin{document}

1\round{2,4}\circled{3}5\circled{6}\circled{7}\circled{8}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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