7

I could not get a proper alignment using either \parbox command or minipage environment as far as wrapping text with figure in the question command or solution environment is concerned. Does anyone knows the solution! I didn't get much help while searching the net in the last few days. Some suggest use of minipage but wrapping text with figure seems impossible in exam class. My MWE goes [while using \noprintanswers command, worst is while using \printanswers command]:

\documentclass{exam}
\usepackage{siunitx}
\usepackage{amssymb,amsmath,amsthm} 
% For drawing circuits
\usepackage{tikz,blindtext}
% For drawing flow graph
\usetikzlibrary{arrows,circuits.ee.IEC,positioning}
\usetikzlibrary{decorations.markings}
% For using circuitikz library
\usepackage[american voltages, american currents,siunitx]{circuitikz}
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\usepackage{caption}
\captionsetup[figure]{% 
    name=Fig.,  % To change figure name from "Figure" to "Fig.".
    font=footnotesize,
    textfont=it,
    justification=justified,
    singlelinecheck=true,
%   subrefformat=parens,
    width=0.3\textwidth,
%   labelformat=brace,
}%
\usepackage{wrapfig}
\pointsinrightmargin%
%|||||| Printing Answers ||||||<<<<<<<=======================
\printanswers
%\noprintanswers

\begin{document}
\begin{questions}
% Q1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
\question[5]     \label{Q:Q1} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi viverra enim vulputate quam cursus, nec accumsan nisi vestibulum. Cras quis risus eleifend, consectetur neque laoreet, faucibus ligula. Donec congue tortor ligula, sit amet dictum augue pharetra a.%
\begin{wrapfigure}{r}{0.5\textwidth}
\hfill%
\centering%
\scalebox{0.8}{%
\begin{tikzpicture}[circuit ee IEC,x=3cm,y=1.5cm, semithick, every info/.style={font=\footnotesize}, small circuit symbols, set resistor graphic=var resistor IEC graphic, set diode graphic=var diode IEC graphic, set make contact graphic= var make contact IEC graphic]
    \draw (0.5,0) to (0,0.0) to [I, l=2<\ampere>] (0,2.0) to (0.5,2.0);
    \draw (0.5,2.0) to [R, l_=15<\ohm>] (1.5,2.0);
    \draw (0.5,0) to [R,l=3<\ohm>,*-*] (0.5,1.0);
    \draw (0.5,1.0) to [R,l=7<\ohm>,-*] (0.5,2.0);
    \draw (1.5,0.0) to [R,l=5<\ohm>,*-*] (1.5,2.0);
    \draw (1.5,0) to (2.0,0) to [V,l_=3.5<\volt>] (2.0,2.0) to (1.5,2.0);
    \draw (0.5,0) to (1.5,0);
    \draw[magenta,->] (0.8,2.3) to node[above]{$i_x$} (1.2,2.3);
\end{tikzpicture}}% end of scalebox
\captionof{figure}{Circuit for Q.\ref{Q:Q1}}
\label{fig:q1}
\end{wrapfigure}
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Q2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\question[5] \parbox[t]{0.5\linewidth}{%
Find the value of $i_x$ in the circuit of Fig.~\ref{fig:q2}. Aliquam mi odio, feugiat quis efficitur non, suscipit in est. In hac habitasse platea dictumst. Praesent a arcu ac mi ullamcorper sollicitudin at nec ligula. Phasellus ut tempor felis. Mauris aliquet eros sit amet metus venenatis, id hendrerit sapien venenatis. Nam a augue ligula. Morbi mattis purus ac ipsum vehicula vehicula. Nullam sit amet bibendum lacus, at lacinia ligula.%
\label{Q:Q2}
}\hfill%
\parbox[h]{0.5\linewidth}{%
\hfill%
\centering%
\scalebox{0.8}{%
\begin{tikzpicture}[circuit ee IEC,x=3cm,y=1.5cm, semithick, every     info/.style={font=\footnotesize}, small circuit symbols, set resistor graphic=var resistor IEC graphic, set diode graphic=var diode IEC graphic, set make contact graphic= var make contact IEC graphic]
    \draw (0.5,0) to (0,0.0) to [I, l=2<\ampere>] (0,2.0) to (0.5,2.0);
    \draw (0.5,2.0) to [R, l_=15<\ohm>] (1.5,2.0);
    \draw (0.5,0) to [R,l=3<\ohm>,*-*] (0.5,1.0);
    \draw (0.5,1.0) to [R,l=7<\ohm>,-*] (0.5,2.0);
    \draw (1.5,0.0) to [R,l=5<\ohm>,*-*] (1.5,2.0);
    \draw (1.5,0) to (2.0,0) to [V,l_=3.5<\volt>] (2.0,2.0) to (1.5,2.0);
    \draw (0.5,0) to (1.5,0);
    \draw[magenta,->] (0.8,2.3) to node[above]{$i_x$} (1.2,2.3);
\end{tikzpicture}}% end of scalebox
\captionof{figure}{Circuit for Q.\ref{Q:Q2}}
\label{fig:q2}
}
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
% Reset figure numbering to default style for next question
\renewcommand{\thefigure}{\thequestion}     %<<>><<>><<>><>>
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Q3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
\question[5] \label{Q:Q3}\begin{minipage}[c]{0.5\linewidth}
\raggedright\setlength{\parskip}{0.1in}
Pellentesque augue massa, euismod a lorem sit amet, commodo vulputate erat. Vestibulum laoreet sagittis lacus eget tempus. Etiam facilisis odio id malesuada faucibus. Quisque eu turpis a dolor rutrum pretium vitae in erat. Maecenas ultricies sit amet sem eget posuere. 
\end{minipage}
\hfill%
\parbox[h]{0.5\linewidth}{%
\hfill%
\centering%
\scalebox{0.8}{%
\begin{tikzpicture}[circuit ee IEC,x=3cm,y=1.5cm, semithick, every info/.style={font=\footnotesize}, small circuit symbols, set resistor graphic=var resistor IEC graphic, set diode graphic=var diode IEC graphic, set make contact graphic= var make contact IEC graphic]
    \draw (0.5,0) to (0,0.0) to [I, l=2<\ampere>] (0,2.0) to (0.5,2.0);
    \draw (0.5,2.0) to [R, l_=15<\ohm>] (1.5,2.0);
    \draw (0.5,0) to [R,l=3<\ohm>,*-*] (0.5,1.0);
    \draw (0.5,1.0) to [R,l=7<\ohm>,-*] (0.5,2.0);
    \draw (1.5,0.0) to [R,l=5<\ohm>,*-*] (1.5,2.0);
    \draw (1.5,0) to (2.0,0) to [V,l_=3.5<\volt>] (2.0,2.0) to (1.5,2.0);
    \draw (0.5,0) to (1.5,0);
    \draw[magenta,->] (0.8,2.3) to node[above]{$i_x$} (1.2,2.3);
\end{tikzpicture}}% end of scalebox
\captionof{figure}{Circuit for Q.\ref{Q:Q3}}
\label{fig:q3}
}
\end{questions}
\end{document}

Wraping text with figure!

6
  • You've written \usepackage{wrapfig} but there's no \begin{wrapfigure}...\end{wrapfigure}
    – user31729
    Commented Sep 8, 2015 at 9:38
  • Yes, I forgot to include that. I've just included it. Thanks for pointing it out. Main problem starts from wraping figures with text in exam class. Some suggest to use minipage but it creates alignment problem as seen from question # 3.
    – Khaaba
    Commented Sep 8, 2015 at 9:42
  • 2
    I think, you're out of luck anyway: question is a list-like environment and the wrapfig manual states that one should not use wrapfig inside a list-environment
    – user31729
    Commented Sep 8, 2015 at 9:47
  • Can you please suggest the alignment of "3" in last question with text like earlier questions? I would be happy with that as I can at least put question figure alongside the question number and texts. I have been avoiding this all these while but can't do this little adjustment of question number inline with question texts as far as usage of minipage is concerned.
    – Khaaba
    Commented Sep 8, 2015 at 9:56
  • @Khaaba Isn't my answer what you want? It uses aligned minipages.
    – LaRiFaRi
    Commented Sep 8, 2015 at 10:35

2 Answers 2

4

I would use minipages here. I was too slow so egreg already mentioned the \vspace{-\baselineskip} trick. But I post it anyway.

% arara: pdflatex

\documentclass{exam}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}
\usepackage{blindtext}
\usepackage{microtype}
\usepackage[american voltages,american currents,siunitx]{circuitikz}
\usepackage{caption}
\captionsetup[figure]{% 
    name=Fig.,  % To change figure name from "Figure" to "Fig.".
    font=footnotesize,
    textfont=it,
    justification=justified,
    singlelinecheck=true,
    width=.4\textwidth,
}
\pointsinrightmargin
%|||||| Printing Answers ||||||<<<<<<<=======================
\printanswers
%\noprintanswers

\begin{document}
\begin{questions}
% Q1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
\question[5]\label{Q:Q1}
\begin{minipage}[t]{.5\linewidth}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi viverra enim vulputate quam cursus, nec accumsan nisi vestibulum. Cras quis risus eleifend, consectetur neque laoreet, faucibus ligula. Donec congue tortor ligula, sit amet dictum augue pharetra a.
\end{minipage}%
\begin{minipage}[t]{.5\linewidth}
    \vspace{-\baselineskip}
    \centering%
    \begin{tikzpicture}[x=2.61cm,y=1.4cm,circuit ee IEC,every info/.style={font=\footnotesize}, small circuit symbols, set resistor graphic=var resistor IEC graphic, set diode graphic=var diode IEC graphic, set make contact graphic= var make contact IEC graphic]
        \draw (0.5,0) to (0,0.0) to [I, l=2<\ampere>] (0,2.0) to (0.5,2.0);
        \draw (0.5,2.0) to [R, l_=15<\ohm>] (1.5,2.0);
        \draw (0.5,0) to [R,l=3<\ohm>,*-*] (0.5,1.0);
        \draw (0.5,1.0) to [R,l=7<\ohm>,-*] (0.5,2.0);
        \draw (1.5,0.0) to [R,l=5<\ohm>,*-*] (1.5,2.0);
        \draw (1.5,0) to (2.0,0) to [V,l_=3.5<\volt>] (2.0,2.0) to (1.5,2.0);
        \draw (0.5,0) to (1.5,0);
        \draw[magenta,->] (0.8,2.3) to node[above]{$i_x$} (1.2,2.3);
    \end{tikzpicture}%
    \captionof{figure}{Circuit for Q.\ref{Q:Q1}}
    \label{fig:q1}
\end{minipage}%
% Q2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\question[5]\label{Q:Q2}
\begin{minipage}[t]{.5\linewidth}
    Find the value of $i_x$ in the circuit of Fig.~\ref{fig:q2}. Aliquam mi odio, feugiat quis efficitur non, suscipit in est. In hac habitasse platea dictumst. Praesent a arcu ac mi ullamcorper sollicitudin at nec ligula. Phasellus ut tempor felis. Mauris aliquet eros sit amet metus venenatis, id hendrerit sapien venenatis. Nam a augue ligula. Morbi mattis purus ac ipsum vehicula vehicula. Nullam sit amet bibendum lacus, at lacinia ligula.%
\end{minipage}%
\begin{minipage}[t]{.5\linewidth}
    \vspace{-\baselineskip}
    \centering
    \begin{tikzpicture}[x=2.61cm,y=1.4cm,circuit ee IEC, every info/.style={font=\footnotesize}, small circuit symbols, set resistor graphic=var resistor IEC graphic, set diode graphic=var diode IEC graphic, set make contact graphic= var make contact IEC graphic]
        \draw (0.5,0) to (0,0.0) to [I, l=2<\ampere>] (0,2.0) to (0.5,2.0);
        \draw (0.5,2.0) to [R, l_=15<\ohm>] (1.5,2.0);
        \draw (0.5,0) to [R,l=3<\ohm>,*-*] (0.5,1.0);
        \draw (0.5,1.0) to [R,l=7<\ohm>,-*] (0.5,2.0);
        \draw (1.5,0.0) to [R,l=5<\ohm>,*-*] (1.5,2.0);
        \draw (1.5,0) to (2.0,0) to [V,l_=3.5<\volt>] (2.0,2.0) to (1.5,2.0);
        \draw (0.5,0) to (1.5,0);
        \draw[magenta,->] (0.8,2.3) to node[above]{$i_x$} (1.2,2.3);
    \end{tikzpicture}%
    \captionof{figure}{Circuit for Q.\ref{Q:Q2}}
    \label{fig:q2}
\end{minipage}%
% Q3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
\question[5]\label{Q:Q3}
\begin{minipage}[t]{.5\linewidth}
    Find the value of $i_x$ in the circuit of Fig.~\ref{fig:q2}. Aliquam mi odio, feugiat quis efficitur non, suscipit in est. In hac habitasse platea dictumst. Praesent a arcu ac mi ullamcorper sollicitudin at nec ligula. Phasellus ut tempor felis. Mauris aliquet eros sit amet metus venenatis, id hendrerit sapien venenatis. Nam a augue ligula. Morbi mattis purus ac ipsum vehicula vehicula. Nullam sit amet bibendum lacus, at lacinia ligula.%
\end{minipage}%
\begin{minipage}[t]{.5\linewidth}
    \vspace{-\baselineskip}
    \centering
    \begin{tikzpicture}[x=2.61cm,y=1.4cm,circuit ee IEC,every info/.style={font=\footnotesize}, small circuit symbols, set resistor graphic=var resistor IEC graphic, set diode graphic=var diode IEC graphic, set make contact graphic= var make contact IEC graphic]              
        \draw (0.5,0) to (0,0.0) to [I, l=2<\ampere>] (0,2.0) to (0.5,2.0);
        \draw (0.5,2.0) to [R, l_=15<\ohm>] (1.5,2.0);
        \draw (0.5,0) to [R,l=3<\ohm>,*-*] (0.5,1.0);
        \draw (0.5,1.0) to [R,l=7<\ohm>,-*] (0.5,2.0);
        \draw (1.5,0.0) to [R,l=5<\ohm>,*-*] (1.5,2.0);
        \draw (1.5,0) to (2.0,0) to [V,l_=3.5<\volt>] (2.0,2.0) to (1.5,2.0);
        \draw (0.5,0) to (1.5,0);
        \draw[magenta,->] (0.8,2.3) to node[above]{$i_x$} (1.2,2.3);
    \end{tikzpicture}%
    \captionof{figure}{Circuit for Q.\ref{Q:Q3}}
    \label{fig:q2}
\end{minipage}%
\end{questions}
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
% Reset figure numbering to default style for next question
\renewcommand{\thefigure}{\thequestion}     %<<>><<>><<>><>>
\end{document}

enter image description here

1
  • Of course, in this case minipage and \parbox are completely equivalent.
    – egreg
    Commented Sep 8, 2015 at 11:08
4

The wrapfigure environment doesn't work with lists. It's surely better to use \parbox.

Note that h is not a valid specifier for \parbox, that only accepts c (default), t or b. In this case I back up vertically by one line, because the picture seems to occupy more space than it actually does. The initial \vspace also sets the reference point for the vertical alignment.

\documentclass{exam}
\usepackage{siunitx}
\usepackage{amssymb,amsmath,amsthm} 
% For drawing circuits
\usepackage{tikz,blindtext}
% For drawing flow graph
\usetikzlibrary{arrows,circuits.ee.IEC,positioning}
\usetikzlibrary{decorations.markings}
% For using circuitikz library
\usepackage[american voltages, american currents,siunitx]{circuitikz}
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\usepackage{caption}
\captionsetup[figure]{% 
    name=Fig.,  % To change figure name from "Figure" to "Fig.".
    font=footnotesize,
    textfont=it,
    justification=justified,
    singlelinecheck=true,
%   subrefformat=parens,
    width=0.3\textwidth,
%   labelformat=brace,
}

\pointsinrightmargin%
%|||||| Printing Answers ||||||<<<<<<<=======================
\printanswers
%\noprintanswers

\begin{document}
\begin{questions}
% Q2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\question[5]\label{Q:Q2}
\parbox[t]{0.5\linewidth}{%
  Find the value of $i_x$ in the circuit of Fig.~\ref{fig:q2}. Aliquam mi odio, feugiat quis efficitur 
  non, suscipit in est. In hac habitasse platea dictumst. Praesent a arcu ac mi ullamcorper 
  sollicitudin at nec ligula. Phasellus ut tempor felis. Mauris aliquet eros sit amet metus venenatis, 
  id hendrerit sapien venenatis. Nam a augue ligula. Morbi mattis purus ac ipsum vehicula vehicula. 
  Nullam sit amet bibendum lacus, at lacinia ligula.
}%
\parbox[t]{0.5\linewidth}{%
  \centering
  \vspace{-\baselineskip}% also set the reference point
  \scalebox{0.8}{%
    \begin{tikzpicture}[
    circuit ee IEC,x=3cm,y=1.5cm,
    semithick,
    every info/.style={font=\footnotesize},
    small circuit symbols,
    set resistor graphic=var resistor IEC graphic,
    set diode graphic=var diode IEC graphic,
    set make contact graphic=var make contact IEC graphic
    ]
    \draw (0.5,0) to (0,0.0) to [I, l=2<\ampere>] (0,2.0) to (0.5,2.0);
    \draw (0.5,2.0) to [R, l_=15<\ohm>] (1.5,2.0);
    \draw (0.5,0) to [R,l=3<\ohm>,*-*] (0.5,1.0);
    \draw (0.5,1.0) to [R,l=7<\ohm>,-*] (0.5,2.0);
    \draw (1.5,0.0) to [R,l=5<\ohm>,*-*] (1.5,2.0);
    \draw (1.5,0) to (2.0,0) to [V,l_=3.5<\volt>] (2.0,2.0) to (1.5,2.0);
    \draw (0.5,0) to (1.5,0);
    \draw[magenta,->] (0.8,2.3) to node[above]{$i_x$} (1.2,2.3);
  \end{tikzpicture}}% end of scalebox
  \captionof{figure}{Circuit for Q.\ref{Q:Q2}}\label{fig:q2}
}% end of \parbox

\end{questions}
\end{document}

enter image description here

1
  • I will keep these techniques in my mind. Thanks egreg!
    – Khaaba
    Commented Sep 8, 2015 at 11:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .