如何确保两个小页面中的项目在同一行

如何确保两个小页面中的项目在同一行

通过在我的两个(表格)迷你页面中包含 tikz 图片,我的项目变得混乱。理想情况下,每个项目都有对应的项目(除了左侧表格中最后一个项目有一个空条目)。

另外,如何确保最终的输出在页面水平居中?

\documentclass{article}
\usepackage{tikz}
\usepackage{soul}
\begin{document}
\newenvironment{Myitemize}{
\renewcommand{\labelitemi}{{}}
\begin{itemize}}{\end{itemize}}

\begin{minipage}[t]{0.5\textwidth}
\begin{tabular}[t]{p{6.5cm}}
\multicolumn{1}{c}{\ul{Discrete}} \\
\begin{enumerate}
  \item Probability mass function (p.m.f.) 
\begin{tikzpicture}
        \draw (0,0)--(5,0);
        \draw (1,2)--(1,0);
        \draw (3,1)--(3,0);
        \draw (4,0.8)--(4,0);
\end{tikzpicture}
    \item $f(x)$ gives $Pr(X=x)$
    \item Zero probability $\Rightarrow$ Impossibility
    \item 
\end{enumerate} \\
\end{tabular}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{tabular}[t]{p{6.5cm}}
\multicolumn{1}{c}{\ul{Continuous}}\\
\begin{Myitemize}
  \item Probability density function (p.d.f.) 
\begin{tikzpicture}
    \draw (0,0)--(5,0);
  \draw (0,.7) ..controls (3,2.5) and (4,.8) ..(5,.7);
\end{tikzpicture}
    \item Not so; $Pr(X=x)=0$ always
    \item Zero probability events do occur
    \item Can get positive probability (area under continuous curve) for intervals no matter how small
\end{Myitemize} \\
\end{tabular}
\end{minipage}




\end{document}

答案1

正如 Paul Gessler 所评论的那样,你可以把所有东西都放进去 tabular环境有两 p列,每列宽度为

>{\raggedright\arraybackslash}p{\dimexpr0.5\textwidth-2\tabcolsep-2\arrayrulewidth\relax} 

minipages 根本不需要。您可以进一步使用enumitem包及其resume选项继续编号。我还tikzpicture使用相同的边界框对齐了 s。另一个补充是调整行间距,我已经按行进行了调整。

\documentclass{article}
\usepackage{tikz}
\usepackage{soul}
\usepackage{enumitem,array,showframe}   %% showframe just for demo
\begin{document}
\newenvironment{Myitemize}{%
\renewcommand{\labelitemi}{{}}%
\begin{itemize}[nosep]}{\end{itemize}}

\noindent
\begin{tabular}[t]{>{\raggedright\arraybackslash}p{\dimexpr0.5\textwidth-2\tabcolsep-2\arrayrulewidth\relax}
                   >{\raggedright\arraybackslash}p{\dimexpr0.5\textwidth-2\tabcolsep-2\arrayrulewidth\relax}}
\multicolumn{1}{c}{\ul{Discrete}} & \multicolumn{1}{c}{\ul{Continuous}} \\
\begin{enumerate}[nosep,leftmargin=*,series=mylist]
  \item Probability mass function (p.m.f.)
\begin{tikzpicture}[x=0.93cm]   %% just to get rid of badbox
        \draw (0,0)--(5,0);
        \draw (1,2)--(1,0);
        \draw (3,1)--(3,0);
        \draw (4,0.8)--(4,0);
\end{tikzpicture}
 \end{enumerate} &
\begin{Myitemize}
  \item Probability density function (p.d.f.)
\begin{tikzpicture}[x=0.93cm]   %% just to get rid of badbox
    \draw (0,0)--(5,0);
    \path[use as bounding box] (0,0) rectangle (5,2);  %% to make picture align
    \draw (0,.7) ..controls (3,2.5) and (4,.8) ..(5,.7);
    \end{tikzpicture}
\end{Myitemize} \\[-3ex]
    \begin{enumerate}[nosep,resume*=mylist]
    \item $f(x)$ gives $Pr(X=x)$
    \end{enumerate} &
    \begin{Myitemize}
      \item Not so; $Pr(X=x)=0$ always
    \end{Myitemize}\\[-3ex]
    \begin{enumerate}[nosep,resume*=mylist]
      \item Zero probability $\Rightarrow$ Impossibility
    \end{enumerate} &
    \begin{Myitemize}
      \item Zero probability events do occur
    \end{Myitemize}\\[-3ex]
    \begin{enumerate}[nosep,resume*=mylist]
      \item 
    \end{enumerate}&
    \begin{Myitemize}
      \item Can get positive probability (area under continuous curve) for intervals no matter how small
    \end{Myitemize}\\[-3ex]
    \begin{enumerate}[nosep,resume*=mylist]
      \item
    \end{enumerate}&
 \end{tabular}

\end{document}

在此处输入图片描述

相关内容