Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've got a custom class made for homework assignments, and I'm only just now running into an issue with it.

I made a couple of custom environments for problem/solution pairs, and I used a tabular to format the outside environment. I don't know if it's just the interaction with tikz, but my content is pushing text off the bottom edge of the page, and no new page is being started to hold the extra content.

The following example is a tad on the long side, but it's the only way I can easily demonstrate what's going on.

\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}
share|improve this question
    
...You have discovered the reason for floats:) You need to let your tabulars and figures to float, by enclosing them in table or figure. –  Yiannis Lazarides Feb 21 '13 at 3:21
    
I tried using float for my things, but it complained about not being in an outer \par, or something like that. –  agent154 Feb 21 '13 at 3:27
    
You are on the right track with tidying up everything and defining your own environments. The outer gives an error if you pass a parameter to a macro that has a paragraph. Search for long macro there is quite a bit of a write up on this site. Normally defined as \long\def\mymacro. –  Yiannis Lazarides Feb 21 '13 at 4:03

1 Answer 1

up vote 1 down vote accepted

The problem is that everything is embedded within a tabular environment which cannot be broken across a page boundary. If you get rid of the tabular environment, then things get placed better.

I'd suggest you rethink what you want to accomplish with the tabular envrionment. From your definition, it seems you could replace it with an appropriately modified list environment of some sorts.

You can redefine a list environment as follows

\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}}

The \settowidth here does what your m{\mylen} did.

Tweaking the behavior of a list is, IMHO, quite irksome. Play a bit with parameters \labelsep, \labelwidth, and \itemindent and you should get things to work (though sometimes these things act in counter-intuitive ways).

Addendum

This is actually a neat trick to use and it's how a quote environment can be defined (though I think the actual quote environment is defined using \trivlist).

share|improve this answer
    
What might you suggest that I do to restructure this environment? –  agent154 Feb 21 '13 at 3:42
    
That works perfect now.. Thanks a lot. –  agent154 Feb 21 '13 at 4:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.