3

I'd like to have a TikZ figure in a parts-environment, but the figure appears above part (a) instead of below. How can I get the picture to follow the (a)? Thanks for your help!

\documentclass[addpoints,12pt]{exam}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath, amssymb, amsmath}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usepackage{siunitx}

\begin{document}

\begin{questions}
    \question
        Find $x\in \mathbb{Q}$.
        \begin{parts}
            \part 
                \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
                        \clip(-2.0992637227845954,-1.7878880377249167) rectangle (7.801609010358657,5.493825659968799);
                       \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--6.6108--1.8599999999999999*\x)/3.96});
                       \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--3.4032-0.72*\x)/4.2});
                       \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--7.455599999999999-2.58*\x)/0.23999999999999977});
                       \draw (2.75,1.5) node {\rotatebox{60}{$\parallel$}};
                       \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--13.01549181869475-2.58*\x)/0.23999999999999977});
                       \draw (4.85,1.8) node {\rotatebox{60}{$\parallel$}};
                       \draw (3,3.15) node[anchor=north west] {$\SI{1.5}{cm}$};
                       \draw (5.114713103302678,2.140850515449367) node[anchor=north west] {$x$};
                       \draw (0.28281626204234456,1.9263504220289323) node[anchor=north west] {$\SI{3}{cm}$};
                   \end{tikzpicture}
               \part
        \end{parts} 
\end{questions}

\end{document}

Here's a picture:

enter image description here

Torbjørn T.
  • 206,688
thoas
  • 33

3 Answers3

3

You can add baseline=(current bounding box.north) to the options of the tikzpicture.

\documentclass[addpoints,12pt]{exam}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath, amssymb, amsmath}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usepackage{siunitx}

\begin{document}

\begin{questions}
    \question
        Find $x\in \mathbb{Q}$.
        \begin{parts}
            \part 
                \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm,baseline=(current bounding box.north)]
                        \clip(-2.0992637227845954,-1.7878880377249167) rectangle (7.801609010358657,5.493825659968799);
                       \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--6.6108--1.8599999999999999*\x)/3.96});
                       \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--3.4032-0.72*\x)/4.2});
                       \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--7.455599999999999-2.58*\x)/0.23999999999999977});
                       \draw (2.75,1.5) node {\rotatebox{60}{$\parallel$}};
                       \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--13.01549181869475-2.58*\x)/0.23999999999999977});
                       \draw (4.85,1.8) node {\rotatebox{60}{$\parallel$}};
                       \draw (3,3.15) node[anchor=north west] {$\SI{1.5}{cm}$};
                       \draw (5.114713103302678,2.140850515449367) node[anchor=north west] {$x$};
                       \draw (0.28281626204234456,1.9263504220289323) node[anchor=north west] {$\SI{3}{cm}$};
                   \end{tikzpicture}
               \part
        \end{parts} 
\end{questions}

\end{document}

enter image description here

Torbjørn T.
  • 206,688
  • That's pretty neat! Is there an option to center the image? I tried to place the tikz-figure in a center environment, but the (b) got centered too. Placing the figure in a figure environment and using the \centering command didn't help either. – thoas May 01 '14 at 18:41
  • 1
    That is a very different question actually, but you can try adding \hspace*{\fill} just before and just after the tikzpicture – Torbjørn T. May 01 '14 at 18:55
2

Pictures are aligned to their bottoms (baseline). The \savebox is used to compute the height of the picture in order to lower it below part a.

\documentclass[addpoints,12pt]{exam}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath, amssymb, amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{siunitx}
\usepackage{graphics,mwe}% for image

\newsavebox{\hold}
\newlength{\holdht}
\newcommand{\lowerit}[1]{% #1 = picture
\savebox{\hold}{#1}%
\settoheight{\holdht}{\usebox{\hold}}%
\raisebox{-\holdht}{\usebox{\hold}}%
}

\begin{document}

\begin{questions}
    \question
        Find $x\in \mathbb{Q}$.
        \begin{parts}
            \part
            \lowerit{
                \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
                \clip(-2.0992637227845954,-1.7878880377249167) rectangle (7.801609010358657,5.493825659968799);
                \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--6.6108--1.8599999999999999*\x)/3.96});
                \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--3.4032-0.72*\x)/4.2});
                \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--7.455599999999999-2.58*\x)/0.23999999999999977});
                \draw (2.75,1.5) node {\rotatebox{60}{$\parallel$}};
                \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--13.01549181869475-2.58*\x)/0.23999999999999977});
                \draw (4.85,1.8) node {\rotatebox{60}{$\parallel$}};
                \draw (3,3.15) node[anchor=north west] {$\SI{1.5}{cm}$};
                \draw (5.114713103302678,2.140850515449367) node[anchor=north west] {$x$};
                \draw (0.28281626204234456,1.9263504220289323) node[anchor=north west] {$\SI{3}{cm}$};
                \end{tikzpicture}
              }
           \part
             \lowerit{
               \includegraphics{image}
             }
       \end{parts}
\end{questions}

\end{document}

exam class

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
2

\raisebox{-\height}{<content>}shifts its content under the current baseline.

\documentclass[addpoints,12pt]{exam}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath, amssymb, amsmath}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usepackage{siunitx}

\begin{document}

\begin{questions}
    \question
        Find $x\in \mathbb{Q}$.
  \begin{parts}
    \part
      \raisebox{-\height}{%
        \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
         \clip(-2.0992637227845954,-1.7878880377249167) rectangle (7.801609010358657,5.493825659968799);
         \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--6.6108--1.8599999999999999*\x)/3.96});
         \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--3.4032-0.72*\x)/4.2});
         \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--7.455599999999999-2.58*\x)/0.23999999999999977});
         \draw (2.75,1.5) node {\rotatebox{60}{$\parallel$}};
         \draw [domain=-2.0992637227845954:7.801609010358657] plot(\x,{(--13.01549181869475-2.58*\x)/0.23999999999999977});
         \draw (4.85,1.8) node {\rotatebox{60}{$\parallel$}};
         \draw (3,3.15) node[anchor=north west] {$\SI{1.5}{cm}$};
         \draw (5.114713103302678,2.140850515449367) node[anchor=north west] {$x$};
         \draw (0.28281626204234456,1.9263504220289323) node[anchor=north west] {$\SI{3}{cm}$};
        \end{tikzpicture}%
      } 
    \part
  \end{parts} 
\end{questions}

\end{document}

enter image description here

esdd
  • 85,675