![考试类别中的 \parbox、minipage 和 wrapfigure 问题](https://linux22.com/image/318660/%E8%80%83%E8%AF%95%E7%B1%BB%E5%88%AB%E4%B8%AD%E7%9A%84%20%5Cparbox%E3%80%81minipage%20%E5%92%8C%20wrapfigure%20%E9%97%AE%E9%A2%98.png)
就问题命令或解决方案环境中的文本与图形换行而言,我无法使用 \parbox 命令或 minipage 环境获得正确的对齐。有人知道解决方案吗!在过去几天里,我在网上搜索时没有得到太多帮助。有人建议使用 minipage,但在考试课上用图形换行文本似乎是不可能的。我的 MWE 是 [使用 \noprintanswers 命令时,最糟糕的是使用 \printanswers 命令时]:
\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}
答案1
我会minipage
在这里使用 s。我太慢了,所以 egreg 已经提到了这个\vspace{-\baselineskip}
技巧。但我还是发布了它。
% 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}
答案2
该wrapfigure
环境不支持列表。使用 肯定更好\parbox
。
请注意,h
不是 的有效说明符\parbox
,它仅接受c
(默认)t
或b
。在本例中,我将垂直方向后退一行,因为图片似乎比实际占用更多空间。初始值\vspace
还设置了垂直对齐的参考点。
\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}