4

I am making a big list of exercises and I'd like to box the number of the exercise at each line.

I found this:

\tikzstyle{square}=[minimum width=0.5cm,
  minimum height=0.3cm,
  rectangle,
  rounded corners=1pt,
  draw,
  text=Blue,
  font=\bfseries]

  \newcommand{\square}[2]{%
    \begin{tikzpicture} \node[square] (N) at (0,0) {\bfseries $#1$};
    \end{tikzpicture}}

  \square{345} bla bla bla

I am almost satisfied but the square is not aligned with my bla bla bla.

How can I get the box aligned?

Werner
  • 603,163
Damien L
  • 621

2 Answers2

6

Combine anchor=base and the baseline option (no need to name the node).

Code

\documentclass{article}
\usepackage{tikz,bm}
\tikzset{square/.style={
  minimum width=0.5cm,
  minimum height=0.3cm,
  shape=rectangle,
  rounded corners=1pt,
  draw,
  text=blue,
  font=\boldmath,
  anchor=base}}
\newcommand*{\square}[2][]{\tikz[baseline]{\node[square,#1] {$#2$};}}
\begin{document}
\square{345} bla bla bla
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
3

I suggest you to use:

\documentclass{article}
\usepackage{color}


\begin{document}

{\colorbox{yellow}{345}} - blah blah blah

\end{document}

Output:

enter image description here