3

I'm making a multiple choice question and answer. How do I make an appropriate shape (probably an ellipse, oval, or rectangle in this case) around the correct answer without messing with the text alignment?

\documentclass{article}

\usepackage{tikz}

\begin{document}

Two plus thirteen equals FIVE/NINETEEN/\tikz \node[draw,circle]{FIFTEEN}; /NINETY

\end{document}

this doesn't look right...

3

The baseline for a TikZ picture is the bottom of the picture, but you can reset that baseline in the options to the call to \tikz

\documentclass{article}

\usepackage{tikz}

\begin{document}

Two plus thirteen equals FIVE/NINETEEN/\tikz[baseline=(word.base)] \node[draw,circle] (word) {FIFTEEN}; /NINETY

\end{document}

enter image description here

But this will nevertheless interfere with the interline spacing if there is a following line:

enter image description here

Unless you've got a lot of white space around what you're going to circle, I don't thinking circling is going to be the right choice. I would actually define a control sequence to handle this because then within the control sequence you can do a few things that AFAIK you can't do with \tikz....;.

\documentclass{article}

\usepackage{tikz}
\usepackage{lipsum}

\newcommand\circleanswer[1]{%%
  \begin{tikzpicture}[baseline=(word.base)]
    \node[inner sep=0pt]  (word) {#1};
    \begin{pgfinterruptboundingbox}
    \node[draw] at (word) {\phantom{#1}};
    \end{pgfinterruptboundingbox}
  \end{tikzpicture}}

\begin{document}

Two plus thirteen equals FIVE/NINETEEN/\circleanswer{FIFTEEN}/NINETY

\lipsum[1]

\end{document}

I suppose you might try something with an overlay, but in the above code, I basically prevent the bounding box from being enlarged over what was need for the word node.

enter image description here

| improve this answer | |
  • Thank you so much for this! I've started to use the code, but I don't really understand how it works. ATM, my main questions are: (1) What is the whole baseline=(word.base) part doing?, (2) What is a pgfinterruptboundingbox? – WeCanLearnAnything Dec 20 '15 at 1:19
  • @WeCanLearnAnything Regarding baseline=(word.base). A picture has a baseline that by default lies on the bottom of edge of the bounding box. TikZ allows you to reset the baseline which is what this directive does. – A.Ellett Dec 20 '15 at 18:39
  • @WeCanLearnAnything Regarding pgfinterruptboundingbox. The TikZ picture lies within a bounding box which determines its dimensions within the LaTeX document. With each stroked path and creation of nodes, TikZ further updates the bounding box's dimensions. pgfinterruptboundingbox tells TikZ not to update the bounding box dimensions and thus the picture can bleed out into the surrounding area. – A.Ellett Dec 20 '15 at 18:42

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.