TeX - LaTeX Asked by weilam06 on March 2, 2021
I am trying to put the figure beside the text in exam class using minipage
. The best I can do currently is as the following:
With the MWE:
usepackage[a4paper, top=1.9cm, left=2cm, right=2cm, bottom=2.2cm]{geometry}
usepackage{xeCJK}
usepackage{amsmath}
usepackage{amssymb,amsthm}
usepackage{graphicx}
usepackage{commath}
usepackage{longfbox}
usepackage[nice]{nicefrac}
usepackage{cancel}
usepackage{bigints}
usepackage{hyperref}
usepackage{cases}
usepackage{mathtools}
usepackage{empheq}
usepackage{setspace}
usepackage{enumitem, tasks}
usepackage{multicol}
usepackage{graphicx}
usepackage{systeme}
usepackage{gensymb}
usepackage{tkz-euclide}
usepackage{tikz}
usepackage[justify]{ragged2e}
usepackage{pgfplots}
usepackage[export]{adjustbox}
usepackage{colortbl}
usepackage{wrapfig}
usepackage{tikz-3dplot}
usepackage{fancybox,framed}
usepackage[most]{tcolorbox}
usepackage{caption}
usepackage{bm}
usetikzlibrary{patterns}
captionsetup[table]{name=表格}
usetikzlibrary{angles,quotes}
pgfdeclarepatternformonly{mynewdots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{1pt}{1pt}}{pgfqpoint{1pt}{1pt}}% original definition: pgfqpoint{3pt}{3pt}
{%
pgfpathcircle{pgfqpoint{0pt}{0pt}}{.5pt}%
pgfusepath{fill}%
}%
% A custom arrowhead for use on x, y, z axes
tikzstyle{axisarrow} = [-{Latex[inset=0pt,length=5pt]}]
tikzset{
slope/.code={edefslope{#1}},
slope/.default=0.5,
slope
}
makeatletter
pgfdeclarepatternformonly[tikz@pattern@color,slope]{slant lines}
{pgfpoint{-.1mm/slope}{-.1mm}}
{pgfpoint{1.1mm/slope}{1.1mm}}
{pgfpoint{1mm/slope}{1mm}}
{
pgfsetlinewidth{0.4pt}
pgfpathmoveto{pgfpoint{-.1mm/slope}{-.1mm}}
pgfpathlineto{pgfpoint{1.1mm/slope}{1.1mm}}
pgfsetstrokecolor{tikz@pattern@color}
pgfusepath{stroke}
}
makeatother
lfoot{$copyright$ 2013循人中学版权所有}
rfoot{【机密】}
cfoot{- thepage , - }
newtcolorbox{tcbdoublebox}[1][]{%
enhanced jigsaw,
sharp corners,
hbox,
colback=white,
borderline={1pt}{-2pt}{black},
fontupper={setlength{parindent}{10pt}},
#1
}
pgfplotsset{compat=1.16}
setCJKmainfont[BoldFont=Hei,ItalicFont=Kai]{KaiTi}
usetikzlibrary{decorations.pathreplacing}
usetikzlibrary{calc,backgrounds}
usetikzlibrary{intersections}
usepackage[font=normal,justification=centering]{caption}
usepackage[most]{tcolorbox}
renewcommand{choicelabel}{textbf thechoice , ,}
newenvironment{solutions}
renewcommand{questionshook}{%
setlength{leftmargin}{15pt}%
}
newcommand{ihat}{boldsymbol{hat{imath}}}
newcommand{jhat}{boldsymbol{hat{jmath}}}
newcommand{parallelsum}{mathbin{!/mkern-5mu/!}}
newcommandafterclasspart{renewcommandpartlabel{(thepartno)makebox[0pt]{$ ^ast$}}}
newcommandstandardpart{renewcommandpartlabel{(thepartno)}}
renewcommand{choiceshook}{%
setlength{itemsep}{0pt}
settowidth{leftmargin}{W.hskiplabelsephskip 0em}
}
settasks{label={Alph*}, label-format=bfseries, label-offset = 1em, column-sep = 1.5em, item-indent=2em}
usepackage{xpatch}
xpatchcmd{choices}{penalty -50hskip 1em plus 1emrelax}{hfill}{}{}
renewcommand{baselinestretch}{1.5}
unframedsolutions
makeatletter
DeclareFontFamily{U}{tipa}{}
DeclareFontShape{U}{tipa}{m}{n}{<->tipa10}{}
newcommand{arc@char}{{usefont{U}{tipa}{m}{n}symbol{62}}}%
renewcommand{arc}[1]{mathpalettearc@arc{#1}}
newcommand{arc@arc}[2]{%
sbox0{$m@th#1#2$}%
vbox{
hbox{resizebox{wd0}{height}{arc@char}}
nointerlineskip
box0
}%
}
makeatother
tikzset{
hatch distance/.store in=hatchdistance,
hatch distance=10pt,
hatch thickness/.store in=hatchthickness,
hatch thickness=2pt
}
makeatletter
pgfdeclarepatternformonly[hatchdistance,hatchthickness]{flexible hatch}
{pgfqpoint{0pt}{0pt}}
{pgfqpoint{hatchdistance}{hatchdistance}}
{pgfpoint{hatchdistance-1pt}{hatchdistance-1pt}}%
{
pgfsetcolor{tikz@pattern@color}
pgfsetlinewidth{hatchthickness}
pgfpathmoveto{pgfqpoint{0pt}{0pt}}
pgfpathlineto{pgfqpoint{hatchdistance}{hatchdistance}}
pgfusepath{stroke}
}
makeatother
tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
path [#1]
(tikzinputsegmentfirst) -- (tikzinputsegmentlast);
},
curveto code={
path [#1] (tikzinputsegmentfirst)
.. controls
(tikzinputsegmentsupporta) and (tikzinputsegmentsupportb)
..
(tikzinputsegmentlast);
},
closepath code={
path [#1]
(tikzinputsegmentfirst) -- (tikzinputsegmentlast);
},
},
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {arrow[#1]{stealth}}
}}},
midd arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {arrow[thick,blue]{#1}}
}}},
}
pgfarrowsdeclaredouble{<<s}{>>s}{stealth}{stealth}% double stealth
begin{document}
begin{questions}
setlength{rightpointsmargin}{2.5cm}
pointsdroppedatright
marginpointname{%}
bigskip
question
begin{minipage}{0.65textwidth}
question
begin{parts}
part Figure 1 shows a pyramid $ABCD-E$. Suppose that $AE=13$, $AC=10$. Find the followings:
begin{subparts}
subpart[1] Height $ME$.droppoints
subpart[2] Area of base square $ABCD$.droppoints
subpart[2] Volume of pyramid $ABCD-E$.droppoints
end{subparts}
bigskipbigskipbigskip
part[5] As shown in Figure 2,The horizontal distance between building P and Q are $BC=30$ meters. The angle of elevation from point $A$ to point $C$ and to point $D$ are $45^circ$ and $30^circ$, respectively. If these two building are perpendicular to the ground, find their vertical height. droppoints
end{parts}
end{minipage}
begin{minipage}{0.03textwidth}
textcolor{white}{hello}
end{minipage}
begin{minipage}{0.4textwidth}
raisebox{-7cm}{
begin{tikzpicture}[scale=0.9]
defraio{1.5}
defaltura{3}
defmarca{0.2}
defang{68}
draw[thick] (-raio,0,raio) -- (raio,0,raio) -- (raio,0,-raio);
draw[thick, densely dashed,black!80] (raio,0,-raio) -- (-raio,0,-raio) -- (-raio,0,raio);
node[left] at (-raio,0,raio) {$A$};
node[right] at (raio,0,raio) {$B$};
node[right] at (raio-0.1,0,-raio) {$C$};
node[above] at (-raio-0.2,-0.15,-raio+0.2) {$D$};
node[above] at (0,altura-0.1,0) {$E$};
node[below] at (0,0,0) {$M$};
draw (-marca,0,-marca) -- (marca,0,marca);
draw (marca,0,-marca) -- (-marca,0,marca);
draw[densely dashed] (0,0,0) -- (0,altura,0);
draw[thick] (-raio,0,raio) -- (0,altura,0) -- (raio,0,-raio);
draw[thick] (raio,0,raio) -- (0,altura,0);
draw[thick, densely dashed,black!80] (0,altura,0) -- (-raio,0,-raio);
node at (0.3,-1.05,1.25){Figure 1}; end{tikzpicture}}
bigskipbigskipbigskip
raisebox{-1cm}{
begin{tikzpicture}[scale=0.9,
one end extended/.style={shorten <=-#1},
one end extended/.default=1.5cm,
my angle/.style={
every pic quotes/.append style={text=black},
draw=black!200,
thick,
fill=orange!20,
angle radius=0.6cm,
}]
%tkzGrid
tkzDefPoints{4/1/B, 1.8/1/C, 7.2/1/D, 7.2/0.8/F}
tkzDefShiftPoint[B](135:4){A};
tkzDrawSegment[very thick](C,D);
draw [fill,pattern=north east lines,draw=none] (C) rectangle (F);
draw[thick, pattern=mynewdots, pattern color=purple!40] (2,1) rectangle (3,4.5);
draw[thick, pattern=mynewdots, pattern color=green] (6,1) rectangle (7,2.5);
coordinate (G) at (3,4.5);
coordinate (H) at (6,2.5);
coordinate (I) at (3,1);
coordinate (J) at (6,1);
coordinate (K) at (3.7,2.5);
coordinate (L) at (5,4.5);
node at (G) [above]{$A$};
node at (3,0.9) [below]{$B$};
node at (6,0.9) [below]{$C$};
node at (6.2,2.5) [above=-2.5pt]{$D$};
node at (2.5,2.75) {P};
node at (6.5,1.75) {Q};
draw[dashed] (G)--(H);
draw[dashed](G)--(6,1);
draw[dashed] (G)--(5,4.5);
pic [my angle, anchor=west, "$45^circ$", angle eccentricity=1, thick, fill opacity=0.2, angle radius=1.3cm, fill=blue!40, text opacity=1] {angle=J--G--L};
pic [my angle, anchor=west, "$30^circ$", angle eccentricity=1, thick] {angle=H--G--L};
node at (4.5,0) {Figure 2};
draw[dashed] (G)--(H);
draw[dashed](G)--(6,1);
draw[dashed] (G)--(5,4.5);
tkzDrawSegment[very thick](C,D);
end{tikzpicture}}
end{minipage}
end{questions}
end{document}
You can see that in order to put numbering beside part
, I have forced to put two question
commands, so that one in the beginning and one in the middle. I hope the middle one could disappear, and whose numbered with ‘2’ can be returned to ‘1’. On the other hand, I could not figure out any code syntax so that my tikzpicture
can be well located at the right of each subquestion. I have to adjust many times, using raisebox
to each minipage — This is quite inefficient especially I need to deal with many questions.
Is there any ways to solve my question? Thanks for help.
The problem is that exam class uses lists which expect a constant width, especially to print points. OTOH, you can use paracol to put figures into a separate column and sync them up.
To change the width you could save all the counters to global macros (e.g. xdeflastquestion{number{question}}
), end all the environments including paracol, then restart them all using the saved counter values (e.g. setcounter{question}{lastquestion}
)
documentclass{exam}
usepackage[a4paper, top=1.9cm, left=2cm, right=2cm, bottom=2.2cm]{geometry}
usepackage{mathtools}
usepackage{graphicx}
usepackage{paracol}
setcolumnwidth{0.65textwidth}
begin{document}
begin{paracol}{2}
begin{questions}
setlength{rightpointsmargin}{2.5cm}
pointsdroppedatright
marginpointname{%}
bigskip
question
begin{parts}
part Figure ref{test1} shows a pyramid $ABCD-E$. Suppose that $AE=13$, $AC=10$. Find the followings:
begin{subparts}
subpart[1] Height $ME$.droppoints
subpart[2] Area of base square $ABCD$.droppoints
subpart[2] Volume of pyramid $ABCD-E$.droppoints
end{subparts}
switchcolumn
begin{figure}[ht]
includegraphics[width=linewidth]{example-image-a}
caption{}label{test1}
end{figure}
switchcolumn*
part[5] As shown in Figure ref{test2} ... If these two building are perpendicular to the ground, find their vertical height. droppoints
switchcolumn
begin{figure}[ht]
includegraphics[width=linewidth]{example-image-b}
caption{}label{test2}
end{figure}
switchcolumn*
end{parts}
end{questions}
end{paracol}
end{document}
Correct answer by John Kormylo on March 2, 2021
Here is a workabout for what you want.
Your problem comes from the minipage
environment. By default, its alignment is centered on the baseline, but you could change this alignment using the optional argument of minipage
. begin{minipage}[align]{width}
. The align could be t
for top, c
for center or b
for bottom.
I put the minipage inside the part
and made one line for every part. It'll be easier to align a picture with the corresponding text.
You need to define the baseline of your tikzpicture. By default, it is consider as a big caracter with the baseline at the bottom. There is a key that you could use, as an optional argument to the environment. begin{tikzpicture}[baseline=(some node)]
Then, every part will look like this:
part begin{minipage}[t]{width}
Your text here
end{minipage}
hfill
begin{minipage}[t]{width}
begin{tikzpicture}[baseline=(...)]
your picture here
end{tikzpicture}
end{minipage}
Starting from your code, here is my solution. I used two different nodes to align the pictures, to show different possibilities.
documentclass[draft]{exam}
usepackage[a4paper, top=1.9cm, left=2cm, right=2cm, bottom=2.2cm]{geometry}
usepackage{amsmath}
usepackage{amssymb,amsthm}
usepackage{mathtools}
usepackage{tkz-euclide}
usepackage{tikz}
usepackage{pgfplots}
usetikzlibrary{patterns}
usetikzlibrary{angles,quotes}
pgfdeclarepatternformonly{mynewdots}{pgfqpoint{-1pt}{-1pt}}{pgfqpoint{1pt}{1pt}}{pgfqpoint{1pt}{1pt}}% original definition: pgfqpoint{3pt}{3pt}
{%
pgfpathcircle{pgfqpoint{0pt}{0pt}}{.5pt}%
pgfusepath{fill}%
}%
usetikzlibrary{decorations.pathreplacing}
usetikzlibrary{calc,backgrounds}
usetikzlibrary{intersections}
renewcommand{baselinestretch}{1.5}
begin{document}
begin{questions}
setlength{rightpointsmargin}{2.5cm}
pointsdroppedatright
marginpointname{%}
question
begin{parts}
part
begin{minipage}[t]{0.6linewidth}
Figure 1 shows a pyramid $ABCD-E$. Suppose that $AE=13$, $AC=10$. Find the followings:
begin{subparts}
subpart[1] Height $ME$.droppoints
subpart[2] Area of base square $ABCD$.droppoints
subpart[2] Volume of pyramid $ABCD-E$.droppoints
end{subparts}
end{minipage}
hfill
begin{minipage}[t]{0.3linewidth}
begin{tikzpicture}[scale=0.9,baseline=(current bounding box.north)]
defraio{1.5}
defaltura{3}
defmarca{0.2}
defang{68}
draw[thick] (-raio,0,raio) -- (raio,0,raio) -- (raio,0,-raio);
draw[thick, densely dashed,black!80] (raio,0,-raio) -- (-raio,0,-raio) -- (-raio,0,raio);
node[left] at (-raio,0,raio) {$A$};
node[right] at (raio,0,raio) {$B$};
node[right] at (raio-0.1,0,-raio) {$C$};
node[above] at (-raio-0.2,-0.15,-raio+0.2) {$D$};
node[above] at (0,altura-0.1,0) {$E$};
node[below] at (0,0,0) {$M$};
draw (-marca,0,-marca) -- (marca,0,marca);
draw (marca,0,-marca) -- (-marca,0,marca);
draw[densely dashed] (0,0,0) -- (0,altura,0);
draw[thick] (-raio,0,raio) -- (0,altura,0) -- (raio,0,-raio);
draw[thick] (raio,0,raio) -- (0,altura,0);
draw[thick, densely dashed,black!80] (0,altura,0) -- (-raio,0,-raio);
node at (0.3,-1.05,1.25){Figure 1};
end{tikzpicture}
end{minipage}
% bigskipbigskipbigskip
part[5]
begin{minipage}[t]{0.6linewidth}
As shown in Figure 2,The horizontal distance between building P and Q are $BC=30$ meters. The angle of elevation from point $A$ to point $C$ and to point $D$ are $45^circ$ and $30^circ$, respectively. If these two building are perpendicular to the ground, find their vertical height. droppoints
end{minipage}
hfill
begin{minipage}[t]{0.35linewidth}
begin{tikzpicture}[scale=0.9,
one end extended/.style={shorten <=-#1},
one end extended/.default=1.5cm,
my angle/.style={
every pic quotes/.append style={text=black},
draw=black!200,
thick,
fill=orange!20,
angle radius=0.6cm,
},
baseline=(G)]
%tkzGrid
tkzDefPoints{4/1/B, 1.8/1/C, 7.2/1/D, 7.2/0.8/F}
tkzDefShiftPoint[B](135:4){A};
tkzDrawSegment[very thick](C,D);
draw [fill,pattern=north east lines,draw=none] (C) rectangle (F);
draw[thick, pattern=mynewdots, pattern color=purple!40] (2,1) rectangle (3,4.5);
draw[thick, pattern=mynewdots, pattern color=green] (6,1) rectangle (7,2.5);
coordinate (G) at (3,4.5);
coordinate (H) at (6,2.5);
coordinate (I) at (3,1);
coordinate (J) at (6,1);
coordinate (K) at (3.7,2.5);
coordinate (L) at (5,4.5);
node at (G) [above]{$A$};
node at (3,0.9) [below]{$B$};
node at (6,0.9) [below]{$C$};
node at (6.2,2.5) [above=-2.5pt]{$D$};
node at (2.5,2.75) {P};
node at (6.5,1.75) {Q};
draw[dashed] (G)--(H);
draw[dashed](G)--(6,1);
draw[dashed] (G)--(5,4.5);
pic [my angle, anchor=west, "$45^circ$", angle eccentricity=1, thick, fill opacity=0.2, angle radius=1.3cm, fill=blue!40, text opacity=1] {angle=J--G--L};
pic [my angle, anchor=west, "$30^circ$", angle eccentricity=1, thick] {angle=H--G--L};
node at (4.5,0) {Figure 2};
draw[dashed] (G)--(H);
draw[dashed](G)--(6,1);
draw[dashed] (G)--(5,4.5);
tkzDrawSegment[very thick](C,D);
end{tikzpicture}
end{minipage}
end{parts}
end{questions}
end{document}
Not relevent to the problem, but there are some mistakes in your code. Some packages are loaded twice (graphicx, tcolorbox, caption).
When doing minipage like this, make sure you did'nt exceed the text width. In your code, you have 0.65+0.03+0.40=1.053. This cause an overfull hbox to every line.
Also, when providing a code sample to show the problem, try to make is as small as possible by removing unnecessary package and command. It reduce the risk of compatibility issues. In your example, half the code wasn't useful to the problem and could have been removed.
Answered by Alain Remillard on March 2, 2021
Using tabular
and adjustbox
with the code of John Kormylo's answer, you can get the same output:
documentclass{exam}
usepackage[a4paper, top=1.9cm, left=2cm, right=2cm, bottom=2.2cm]{geometry}
usepackage{mathtools}
usepackage[export]{adjustbox} % <-- it loads graphicx and provides the key 'valign'
usepackage{caption}
begin{document}
begin{questions}
setlength{rightpointsmargin}{2.5cm}
pointsdroppedatright
marginpointname{%}
bigskip
question
begin{parts}
setlength{tabcolsep}{0mm}
part
begin{tabular}[t]{p{0.65linewidth}@{hspace{0.01linewidth}}p{0.34linewidth}}
Figure ref{test1} shows a pyramid $ABCD-E$. Suppose that $AE=13$, $AC=10$. Find the followings:
begin{subparts}
subpart[1] Height $ME$.droppoints
subpart[2] Area of base square $ABCD$.droppoints
subpart[2] Volume of pyramid $ABCD-E$.droppoints
end{subparts} & includegraphics[width=linewidth, valign=t]{example-image-a}
captionof{figure}{}label{test1}
end{tabular}
part[5]
begin{tabular}[t]{p{0.65linewidth}@{hspace{0.01linewidth}}p{0.34linewidth}}
As shown in Figure ref{test2} ... If these two building are perpendicular to the ground, find their vertical height. droppoints
& includegraphics[width=linewidth, valign=t]{example-image-b}
captionof{figure}{}label{test2}
end{tabular}
end{parts}
end{questions}
end{document}
Answered by Diaa on March 2, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP