1

I wish to display a small image (included by includegraphicx) immediately followed by a short text. The problem I have is that the text is not vertically centered relatively to the image. I found a solution using TikZ but that's probably overkill. Besides my TikZ solution is not easily rescalable.

I found many tips for vertical centering on this forum but they were all dealing with rather different situations.

A PDF output summarizes it all :

enter image description here

Here is the source code : I have two files, main.tex and badge.tex.

Contents of main.tex :

\documentclass{article}
\usepackage{tikz}
\usepackage{calc}

\newcommand*{\badge}{%
  \includegraphics[height=\heightof{M}+\heightof{M}]{badge}%
}


\begin{document}

Here is the kind of output I don't want :

{\Huge \badge~Hello World}

\vspace*{1cm}
And here is the kind of output I want :

\begin{tikzpicture}
\node[inner sep=0pt] (badge) at (0,0)
    {\includegraphics[width=.14\textwidth]{badge.pdf}};
\node at (3.2,0) {\Huge Hello World};    
\end{tikzpicture}

\end{document}

Contents of badge.tex :

\documentclass{standalone}
%\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}

\newdimen\myUnit

\setlength{\myUnit}{0.1cm}
\begin{document}
  \begin{tikzpicture}
     \pgfmathsetlengthmacro{\Lone}{60*\myUnit}% 
     \pgfmathsetlengthmacro{\Ltwo}{30*\myUnit}% 
      \pgfmathsetlengthmacro{\Lthree}{10*\myUnit}% 
      \pgfmathsetlengthmacro{\Lfour}{15*\myUnit}% 
     \pgfmathsetlengthmacro{\Lfive}{3*\myUnit}% 
     \pgfmathsetlengthmacro{\Lsix}{2*\myUnit}% 
      \pgfmathsetlengthmacro{\Lseven}{20*\myUnit}% 
      \pgfmathsetlengthmacro{\Leight}{3*\myUnit}% 
     \pgfmathsetlengthmacro{\Rone}{5*\myUnit}%    
      \useasboundingbox (-\myUnit, -\myUnit) (\Lone+2*\Rone+\myUnit, \Ltwo+2*\Rone+\Lthree+\myUnit);  
     \path[draw=cyan]
      (0,\Rone)
      arc[
        at={(\Rone,\Rone)},
        start angle=180,
        delta angle=90,
        radius=\Rone,
      ]
      -- ++(\Lone,0) 
      arc[
        at={(\Rone+\Lone,\Rone)},
        start angle=270,
        delta angle=90,
        radius=\Rone,
      ] 
      -- ++(0,\Ltwo) 
      arc[
        at={(\Rone+\Lone,\Rone+\Ltwo)},
        start angle=0,
        delta angle=90,
        radius=\Rone,
      ] 
     -- ++(0,\Lthree)
     -- ++(-\Lfour,0)
     -- ++(0,-\Lthree)
     -- ++(2*\Lfour-\Lone,0)
     -- ++(0,\Lthree)
     -- ++(-\Lfour,0)
     -- ++(0,-\Lthree)  
      arc[
        at={(\Rone,\Rone+\Ltwo)},
        start angle=90,
        delta angle=90,
        radius=\Rone,
      ] 
     -- ++(0,-\Ltwo) 
      ;  
      \path[draw=cyan] (\Rone+\Lone-\Lfive,\Ltwo+\Lthree-\Lfive+2*\Rone)
       -- ++(2*\Lfive-\Lfour,0)
       -- ++(0,2*\Lfive-2*\Lthree)
       -- ++(\Lfour-2*\Lfive,0)
       -- cycle
       ;
      \path[draw=cyan] (\Rone+\Lfour-\Lfive,\Ltwo+\Lthree-\Lfive+2*\Rone)
       -- ++(2*\Lfive-\Lfour,0)
       -- ++(0,2*\Lfive-2*\Lthree)
       -- ++(\Lfour-2*\Lfive,0)
       -- cycle
       ;
      \path[draw=cyan] (\Rone+\Lone-\Lfive-\Lseven+\Lsix,3*\Leight)
      -- ++(\Lseven,0)
      -- ++(0,\Leight)
      -- ++(-\Lseven,0) 
      -- cycle 
       ;
     \path[draw=cyan] (\Rone+\Lone-\Lfive-\Lseven+\Lsix,5*\Leight)
      -- ++(\Lseven,0)
      -- ++(0,\Leight)
      -- ++(-\Lseven,0) 
      -- cycle 
       ;
     \path[draw=cyan] (\Rone+\Lone-\Lfive-\Lseven+\Lsix,7*\Leight)
      -- ++(\Lseven,0)
      -- ++(0,\Leight)
      -- ++(-\Lseven,0) 
      -- cycle 
       ;
  \pgfmathsetlengthmacro{\Lnine}{8*\myUnit}% 
     \pgfmathsetlengthmacro{\Lten}{8*\myUnit}% 
   \pgfmathsetlengthmacro{\yourUnit}{4*\myUnit}%    
  \pgfmathsetlengthmacro{\xOne}{\yourUnit}% 
 \pgfmathsetlengthmacro{\xTwo}{2*\yourUnit}% 
 \pgfmathsetlengthmacro{\xThree}{\yourUnit}%
  \pgfmathsetlengthmacro{\yOne}{2*\yourUnit}% 
 \pgfmathsetlengthmacro{\yTwo}{\yourUnit}% 
 \pgfmathsetlengthmacro{\yThree}{\yourUnit}%
 \path[draw=cyan] (\Lnine,\Lten)
 -- ++(\xOne,\yOne)
 -- ++(\xTwo,\yTwo)
 -- ++(\xThree,-\yThree) 
 -- ++(\xThree,\yThree) 
 -- ++(\xTwo,-\yTwo)
 -- ++(\xOne,-\yOne)
 -- cycle
 ;
 \path[draw=cyan] (\Lnine+\xOne+\xTwo+\xThree,\Lten+1.5*\yOne+\yTwo+\yThree) ellipse ({\xThree}  and \yOne); 
  \end{tikzpicture}
\end{document}
4

0

Browse other questions tagged .