答案1
你可能想看看pgfplots 包对于曲线。
我实际上不太了解这个软件包或使用它;我既不是数学家,也不是数学老师,也不是熟练的 pgf/tikz 用户。我刚刚看到你的帖子,觉得尝试一下会很有趣。这是我的业余尝试,希望对你有用。
对此有更深了解的人可能会弄清楚如何使用 来正确放置虚线\foreach
,但没关系。而且我尝试的其他部分也有点黑客化。可能是一种更简单的方法。
这些被公然盗取的来自这个相关问题的答案和来自这个不同的问题。
\documentclass{article}
\usepackage[margin=1in]{geometry}
% for the curve figure
\usepackage{pgfplots}
\usetikzlibrary{positioning,calc}
% for the table and the problem numbers
\usepackage{multirow,array}
\usepackage{enumitem}
% needed to plot the curve
\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}
% a counter to use for the problem numbers
% I start at 31 just to match your sample
\newcounter{mycounter}
\setcounter{mycounter}{31}
\begin{document}
\sffamily% sans serif font; not necessary
\raggedright% don't just full justification, also not necessary
\noindent\begin{tabular}{% begin the table
|p{0.5\textwidth}|% first column is that width with vertical bars
>{\refstepcounter{mycounter}% before the second column we up the counter
\begin{enumerate}[nolistsep,leftmargin=1.5em,% then start a list
label=\textbf{\arabic*.},start=\value{mycounter}%
]\item}% then insert an item for the list
p{0.4\textwidth}% second column is this width
<{\end{enumerate}}% end the list at end of column
@{\qquad}|} % put some space on right of right column
\hline % horizontal line
\multicolumn{2}{|l|}{% first cell takes up two columns
\vphantom{\rule{1pt}{10pt}}\textbf{% add a little padding to top
Label the normal distribution curve, then
answer the questions that follow.}} \\ \hline
\multirow{3}{8cm}{% this is the big cell
\smallskip\centering % some space at top, make centered
The ages of the 32 recruits in police academy are normally
distributed with a mean of 27 with a standard deviation of 2.
\smallskip % a little space
\begin{tikzpicture}
\begin{axis}[
domain=21.5:32.5,% x value range
range=0:0.20,% y value range
height=5cm,
width=10cm,
hide x axis,% no axes
hide y axis
]%
% the curve itself
\addplot [very thick] {gauss(x,27,2)};
% line at bottom
\draw [thick] (axis cs:21.5,0) -- (axis cs:32.5,0);
% dashed lines up to curve; I'm sure this can be done a better way
\pgfmathsetmacro\valueMid{gauss(27,27,2)}
\draw [thick, dashed] (axis cs:27,0) -- (axis cs:27,\valueMid);
\pgfmathsetmacro\valueLI{gauss(25.8,27,2)}
\draw [thick, dashed] (axis cs:25.8,0) -- (axis cs:25.8,\valueLI);
\pgfmathsetmacro\valueLM{gauss(24.6,27,2)}
\draw [thick, dashed] (axis cs:24.6,0) -- (axis cs:24.6,\valueLM);
\pgfmathsetmacro\valueLO{gauss(23.4,27,2)}
\draw [thick, dashed] (axis cs:23.4,0) -- (axis cs:23.4,\valueLO);
\pgfmathsetmacro\valueRI{gauss(28.2,27,2)}
\draw [thick, dashed] (axis cs:28.2,0) -- (axis cs:28.2,\valueRI);
\pgfmathsetmacro\valueRM{gauss(29.4,27,2)}
\draw [thick, dashed] (axis cs:29.4,0) -- (axis cs:29.4,\valueRM);
\pgfmathsetmacro\valueRO{gauss(30.6,27,2)}
\draw [thick, dashed] (axis cs:30.6,0) -- (axis cs:30.6,\valueRO);
\end{axis}
\end{tikzpicture}} &
What percent of the recruits are between ages 23 and 27?
\bigskip % put space underneath questions
\\\cline{2-2} % draw horizontal line only in second column
&
What is the probability that a recruit is at least 31 years old?
\bigskip
\\ \cline{2-2}
&
Approximately how many recruits are at most 29 years old?
\bigskip
\\ \hline
\end{tabular}
\end{document}
答案2
欢迎来到 tex.stackexchange!我在这里介绍几个选项:
\begin{myquestion}...\quess...\end{myquestion}
和
\begin{myquestionalt}...\quess...\end{myquestionalt}
第一种使用 Ti钾Z,而第二个使用tabular
。在这两种情况下,图形框架(左侧)中的材料几乎由您决定 - 只要合适,您可以将任何东西放进去。之后的任何内容\quess
(最多\end{...}
都是一个枚举列表,每行以 开头\item
。我在代码中包含了示例。
我主要关心的是让输入问题变得简单,这相当容易。代码已注释,但如果有任何问题,总是可以调整的……
更新
我在环境中添加了一个选项来改变问题的宽度。
\documentclass{article}
\usepackage[]{geometry}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{xparse}
\usepackage{tikz}%% For myquestion
\usepackage{enumitem}
\usepackage{keyval}
\usetikzlibrary{calc,shapes.multipart,positioning,trees,snakes}%% For myquestion
%% Store material for the left and right frames:
\newsavebox\figbox
\newsavebox\quebox
\newcounter{quenum}
\newlength{\qsep}
\newlength{\qwidth}
\setlength{\qsep}{0.25in}%% <<< Set as default spacing between questions>>>
\setlength{\qwidth}{4in}%% <<<Set to the desired defaultzz width>>>
%% |=====8><-----| %%
\makeatletter
\define@key{ques}{qsep}{\setlength{\qsep}{#1}}
\define@key{ques}{qwidth}{\setlength{\qwidth}{#1}}
\makeatother
%% |=====8><-----| %% Uses TikZ and shapes.multipart
\NewDocumentEnvironment{myquestion}{O{}m}{%
\setkeys{ques}{#1}
\stepcounter{quenum}
\begin{lrbox}{\figbox}
\begin{minipage}[t]{\dimexpr0.5\qwidth-12pt\relax}%% to fit \qwidth
}{%
\end{enumerate}
\vspace{\qsep}
\end{minipage}
\end{lrbox}
\noindent
\tikz{%
\node[rectangle split,rectangle split parts=2,rectangle split part align=left,draw] (Q) {%
\nodepart{one}\parbox{\dimexpr\qwidth-12pt\relax}{\bfseries#2}
\nodepart{two}\usebox{\figbox}\quad{\usebox{\quebox}}
};%
\draw (Q.one split) -- (Q.south);
}
}
%% |=====8><-----| %% Uses tabular
\NewDocumentEnvironment{myquestionalt}{O{}m}{%
\setkeys{ques}{#1}
\stepcounter{quenum}
\begin{lrbox}{\figbox}
\begin{minipage}[t]{\dimexpr0.5\qwidth-18pt\relax}%% to fit \qwidth
}{%
\end{enumerate}
\vspace{\qsep}
\end{minipage}
\end{lrbox}
\noindent
\begin{tabular}{|l|l|}
\hline
\multicolumn{2}{|l|}{\textbf{#2}}\\\hline
\usebox{\figbox}&\usebox{\quebox}\\\hline
\end{tabular}
}
\NewDocumentCommand{\quess}{}{% use \item for each question in the right-hand frame
\end{minipage}
\end{lrbox}
%% https://tex.stackexchange.com/questions/21596/resuming-a-list-started-within-a-minipage
\begin{lrbox}{\quebox}
\begin{minipage}[t]{\dimexpr0.5\qwidth-12pt\relax}%% to fit \qwidth
\ifnum\thequenum=1
\begin{enumerate}[nosep,parsep=\qsep,label=\textbf{\arabic*.},leftmargin=*,series=mylist]
\else
\begin{enumerate}[label=\textbf{\arabic*.},resume*=mylist,leftmargin=*]
\fi
}
%% |=====8><-----| %%
% Use:
% \begin{myquestion}{<The title or question>}%% or: \begin{myquestionalt}{<The title or question>}
% contents of the left side for figures, etc
% \quess
% Enumerate questions (use \item)
% \end{myquestion}%% or \end{myquestionalt}
% or, showing optional argument:
% \begin{myquestion}[qsep=0.25in]{<The title or question>} or
% \begin{myquestion}[qsep=0.25in]{<The title or question>}%%
% contents of the left side
% \quess
% Enumerate questions (use \item)
% \end{myquestion}%% or \end{myquestionalt}
\begin{document}
\begin{myquestion}[qwidth=4.5in]{This is a test using Ti\emph{k}Z}%% Uses default qsep
\centering
A Ti\emph{k}z figure on the left
%% https://texample.net/tikz/examples/title-graphics/
\tikzstyle{level 1}=[sibling angle=120]
\tikzstyle{level 2}=[sibling angle=60]
\tikzstyle{level 3}=[sibling angle=30]
\tikzstyle{every node}=[fill]
\tikzstyle{edge from parent}=[snake=expanding waves,segment length=1mm,
segment angle=10,draw]
\scalebox{0.4}{%
\begin{tikzpicture}[grow cyclic,shape=circle,very thick,level distance=13mm,cap=round]
\node {} child [color=\A] foreach \A in {red,green,blue}
{ node {} child [color=\A!50!\B] foreach \B in {red,green,blue}
{ node {} child [color=\A!50!\B!50!\C] foreach \C in {black,gray,white}
{ node {} }
}
};
\end{tikzpicture}
\vspace{0.1in}
}
\quess
\item A first question that might actually be quite lengthy
\item A second question
\item A third question
\end{myquestion}
\begin{myquestion}[qsep=0.5in]{This is another test}%%
A figure on the left
\includegraphics[width=0.5\linewidth]{example-image-a}
\quess
\item A fourth question
\item A fifth question
\item A sixth question
\end{myquestion}
%% |=====8><-----| %%
\setcounter{quenum}{0}%% <<<Use this to start a new series of questions>>>
\begin{myquestionalt}{This is a test using a tabular}
\centering
A Ti\emph{k}z figure on the left
%% https://texample.net/tikz/examples/title-graphics/
\tikzstyle{level 1}=[sibling angle=120]
\tikzstyle{level 2}=[sibling angle=60]
\tikzstyle{level 3}=[sibling angle=30]
\tikzstyle{every node}=[fill]
\tikzstyle{edge from parent}=[snake=expanding waves,segment length=1mm,
segment angle=10,draw]
\scalebox{0.4}{%
\begin{tikzpicture}[grow cyclic,shape=circle,very thick,level distance=13mm,cap=round]
\node {} child [color=\A] foreach \A in {red,green,blue}
{ node {} child [color=\A!50!\B] foreach \B in {red,green,blue}
{ node {} child [color=\A!50!\B!50!\C] foreach \C in {black,gray,white}
{ node {} }
}
};
\end{tikzpicture}\par
}
\vspace{3pt}
\quess
\item A first question
\item A second question
\item A third question
\end{myquestionalt}
\begin{myquestionalt}[qwidth=3.75in,qsep=0.15in]{This is another test}
A figure on the left
\includegraphics[width=0.5\linewidth]{example-image-b}
\quess
\item A fourth question
\item A fifth question
\item A sixth question
\end{myquestionalt}
\end{document}