内容被推离页面,没有开始新的页面

内容被推离页面,没有开始新的页面

我有一个为家庭作业而定制的课程,但现在我遇到了一个问题。

我为问题/解决方案对创建了几个自定义环境,并使用表格来格式化外部环境。我不知道这是否只是与 tikz 的交互,但我的内容将文本推离了页面的底部边缘,并且没有启动新页面来保存额外的内容。

下面的例子有点长,但这是我能够轻松演示正在发生的事情的唯一方法。

\documentclass{article}
\usepackage{circuitikz}
\usepackage{array}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{enumitem}

\newcounter{problem}
\setcounter{problem}{0}

\newlength{\mylen}
\settowidth{\mylen}{100}

\newenvironment{problem}[1][]{%
  \refstepcounter{problem}
  \par\noindent
  \begin{tabular}{m{\mylen}p{\dimexpr\linewidth-\mylen-3\tabcolsep\relax}@{}}
  \arabic{problem}. & \ifx\relax#1\relax \else\textbf{#1}\\[1mm]&\fi
  }
  {\end{tabular}\ignorespacesafterend\medskip}%

\newenvironment{parts}
  {\begin{enumerate}[label=\alph*)]}
  {\end{enumerate}}

\declaretheoremstyle[
    within=section,
    spaceabove=5mm,
    spacebelow=3mm,
    headfont=\bfseries,
    notefont=\normalfont,
    bodyfont=\itshape,
    headpunct=\newline,
    %postheadspace={10pt},
    notebraces={}{},
    headformat=\NAME:
]{proof}

\declaretheorem[style=proof,qed=\qedsymbol,name=Solution]{solution}

\begin{document}
  \begin{problem}[Creating Digital Circuits: The Half Adder]
    We know that the NAND gate is universal, so all other gates can be built using just NAND gates. Hence we should be able to build a half-adder using NAND gates. And we can.
  \begin{parts}
    \item Implement the AND operation as a circuit using only 2 NAND gates. [5 marks]=
    \begin{solution}\leavevmode
      \begin{center}
        \begin{circuitikz} \draw
        (0,2) node[nand port] (nand1) {}
        (2,2) node[nand port] (nand2) {}
        (nand1.in 1) node [anchor=east] {x}
        (nand1.in 2) node [anchor=east] {y}
        (nand1.out) -- (nand2.in 1)
        (nand1.out) -- (nand2.in 2)
        (nand2.out) node [anchor=west] {$\overline{\overline{x\cdot y}\cdot \overline{x\cdot y}}$};
        \end{circuitikz}
      \end{center}
    \end{solution}
    \item Check your design in (a) by showing the full truth table for it. [5 marks]
    \begin{solution}\leavevmode
      \begin{center}
        \begin{tabular}{cccccc}
          $x$ & $y$ & $x\cdot y$ & $\overline{x\cdot y}$ & $\overline{x\cdot y}\cdot \overline{x\cdot y}$ & $\overline{\overline{x\cdot y}\cdot \overline{x\cdot y}}$ \\ 
          0 & 0 & 0 & 1 & 1 & 0 \\ 
          0 & 1 & 0 & 1 & 1 & 0 \\ 
          1 & 0 & 0 & 1 & 1 & 0 \\ 
          1 & 1 & 1 & 0 & 0 & 1 \\ 
        \end{tabular} 
      \end{center}
    \end{solution}
    \item Implement the OR operation as a circuit using only 3 NAND gates. [5 marks]
    \begin{solution}\leavevmode
      \begin{center}
        \begin{circuitikz} \draw
        (0,0) node[nand port] (nand1) {}
        (0,2) node[nand port] (nand2) {}
        (2,1) node[nand port] (nand3) {}
        (nand1.in 1) node [anchor=east] {y}
        (nand1.in 2) node [anchor=east] {y}
        (nand2.in 1) node [anchor=east] {x}
        (nand2.in 2) node [anchor=east] {x}
        (nand1.out) -- (nand3.in 2)
        (nand2.out) -- (nand3.in 1)
        (nand3.out) node [anchor=west] {$\overline{\overline{x\cdot x}\cdot \overline{y\cdot y}}$};
        \end{circuitikz}
      \end{center}
    \end{solution}
    \item Check your design in (c) by showing the full truth table for it. [5 marks]
    \begin{solution}\leavevmode
      \begin{center}
        \begin{tabular}{ccccccccc}
          $x$ & $y$ & $x\cdot y$ & $\overline{x\cdot y}$ & $\overline{x\cdot y}\cdot \overline{x\cdot y}$ & $\overline{\overline{x\cdot y}\cdot \overline{x\cdot y}}$ \\ 
          0 & 0 & 0 & 1 & 1 & 0 \\ 
          0 & 1 & 0 & 1 & 1 & 0 \\ 
          1 & 0 & 0 & 1 & 1 & 0 \\ 
          1 & 1 & 1 & 0 & 0 & 1 \\ 
        \end{tabular} 
      \end{center}
    \end{solution}

    \item By observing that $x\oplus y=(x+y)\cdot(\overline{x\cdot y})$, implement the XOR operation as a circuit using at most 6 NAND gates. [5 marks]
    \begin{solution}

    \end{solution}
    \item Check your design in (e) by showing the full truth table for it. [5 marks]
    \begin{solution}

    \end{solution}
  \end{parts}
  \end{problem}
\end{document}

答案1

问题是,所有内容都嵌入在tabular无法跨页面边界打破的环境中。如果你摆脱了环境tabular,那么事情就会被放置更好的

我建议你重新考虑一下你想用这个tabular环境实现什么。从你的定义来看,似乎你可以用某种经过适当修改的列表环境来替换它。

您可以按如下方式重新定义列表环境

\newenvironment{problem}[1][]{%
  \refstepcounter{problem}%
  \begin{list}{\arabic{problem}.}
              {\settowidth{\labelwidth}{100}%
               \setlength{\rightmargin}{0pt}%
              }
    \item \ifx\relax#1\relax \else\textbf{#1}\\[1mm]\fi
    }
    {\end{list}}

这里执行的\settowidth操作与您m{\mylen}所执行的操作相同。

在我看来,调整列表的行为相当烦人。稍微调整一下参数\labelsep\labelwidth\itemindent,您就应该可以让它正常工作(尽管有时这些事情会以违反直觉的方式发生)。

附录

这实际上是一个巧妙的技巧,它就是如何quote定义环境(尽管我认为实际quote环境是使用定义的\trivlist)。

相关内容