我正在尝试使用 将图形放在考试课上的文本旁边\minipage
。我目前能做的最好的事情如下:
使用 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={\edef\slope{#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/\!}}
\newcommand\afterclasspart{\renewcommand\partlabel{(\thepartno)\makebox[0pt]{$\ ^\ast$}}}
\newcommand\standardpart{\renewcommand\partlabel{(\thepartno)}}
\renewcommand{\choiceshook}{%
\setlength{\itemsep}{0pt}
\settowidth{\leftmargin}{W.\hskip\labelsep\hskip 0em}
}
\settasks{label={\Alph*}, label-format=\bfseries, label-offset = 1em, column-sep = 1.5em, item-indent=2em}
\usepackage{xpatch}
\xpatchcmd{\choices}{\penalty -50\hskip 1em plus 1em\relax}{\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]{\mathpalette\arc@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.65\textwidth}
\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}
\bigskip\bigskip\bigskip
\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.03\textwidth}
\textcolor{white}{hello}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\raisebox{-7cm}{
\begin{tikzpicture}[scale=0.9]
\def\raio{1.5}
\def\altura{3}
\def\marca{0.2}
\def\ang{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}}
\bigskip\bigskip\bigskip
\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}
可以看到,为了在旁边加上编号\part
,我强行放了两个\question
命令,一个在开头,一个在中间。我希望中间的那个可以消失,编号为“2”的命令可以恢复为“1”。另一方面,我无法想出任何代码语法,以便我的tikzpicture
可以很好地位于每个子问题的右侧。我不得不多次调整,使用\raisebox
每个小页面——这非常低效,尤其是我需要处理许多问题时。
有什么方法可以解决我的问题吗?谢谢帮助。
答案1
问题是考试类使用的列表需要恒定的宽度,尤其是打印点时。另一方面,您可以使用 paracol 将数字放入单独的列并同步它们。
要更改宽度,您可以将所有计数器保存到全局宏(例如\xdef\lastquestion{\number{question}}
),结束包括 paracol 在内的所有环境,然后使用保存的计数器值重新启动它们(例如\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.65\textwidth}
\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}
答案2
使用tabular
并adjustbox
与 John Kormylo 答案的代码一起使用,您可以获得相同的输出:
\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.65\linewidth}@{\hspace{0.01\linewidth}}p{0.34\linewidth}}
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.65\linewidth}@{\hspace{0.01\linewidth}}p{0.34\linewidth}}
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}
答案3
这是关于您想要的内容的工作。
您的问题来自minipage
环境。默认情况下,其对齐方式以基线为中心,但您可以使用可选参数更改此对齐方式minipage
。\begin{minipage}[align]{width}
对齐可以是t
顶部、c
中心或b
底部。
我把小页面放在里面\part
,每部分占一行。这样可以更轻松地将图片与相应的文本对齐。
您需要定义 tikzpicture 的基线。默认情况下,它被视为一个大字符,基线位于底部。您可以使用一个键作为环境的可选参数。\begin{tikzpicture}[baseline=(some node)]
然后,每个部分看起来都会像这样:
\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}
从您的代码开始,这是我的解决方案。我使用两个不同的节点来对齐图片,以显示不同的可能性。
\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.6\linewidth}
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.3\linewidth}
\begin{tikzpicture}[scale=0.9,baseline=(current bounding box.north)]
\def\raio{1.5}
\def\altura{3}
\def\marca{0.2}
\def\ang{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}
% \bigskip\bigskip\bigskip
\part[5]
\begin{minipage}[t]{0.6\linewidth}
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.35\linewidth}
\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}
与问题无关,但您的代码中存在一些错误。一些包被加载了两次(graphicx、tcolorbox、caption)。
进行这样的缩减页面时,请确保没有超出文本宽度。在您的代码中,有 0.65+0.03+0.40=1.08。这会导致每行的水平盒子都溢出。
此外,在提供代码示例来展示问题时,请尝试通过删除不必要的包和命令来使其尽可能小。这可以降低兼容性问题的风险。在您的示例中,一半的代码对问题没有用,可以删除。