3

I am trying to modify some code that WeBWorK uses to generate pdf hard copies of students' online math assignments. My aim is to improve WeBWorK's accessibility.

My task at the moment is to endow tables with captions. Currently, tables are produced like the first one in the mwe below. I've tried a lot of things to insert a caption well, and the second table demonstrates the best I have been able to produce.

enter image description here

The problem is what I see in the third table, where the only thing different is that there is a caption that is longer than the sum of the subsequent column widths. In this case, what I have does not center the caption. Also, it would be better to keep the columns just as separated as they are in the first two tables.

I'd need to stick with plain tex. Is there a one-size fits all solution to my problem?

\batchmode
\documentclass{amsart}


\begin{document}


\par\medskip\centerline{\kern 1pt\vbox{\halign{#\hfil&&\kern 1em #\hfil\cr
\hfil \(x\)&\hfil \(y\)\cr
\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}&\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}\cr
\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}&\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}\cr}}\kern 0pt}\medskip

%----------------------------

\par\medskip\centerline{\kern 1pt\vbox{\halign{#\hfil&&\kern 1em #\hfil\cr
\omit\hfil\multispan2{caption}\hfil\cr
\hfil \(x\)&\hfil \(y\)\cr
\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}&\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}\cr
\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}&\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}\cr}}\kern 0pt}\medskip

%----------------------------

\par\medskip\centerline{\kern 1pt\vbox{\halign{#\hfil&&\kern 1em #\hfil\cr
\omit\hfil\multispan2{caption that is very long}\hfil\cr
\hfil \(x\)&\hfil \(y\)\cr
\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}&\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}\cr
\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}&\hfil \mbox{\parbox[t]{4ex}{\hrulefill}}\cr}}\kern 0pt}\medskip


\end{document}
  • Why should you stick to Plain when you have \documentclass{amsart}? – egreg Mar 18 '14 at 0:27
  • @egreg I'm not 100% sure. I think that I have to consider that a hundred students might each be asking the server to generate a pdf with a hundred problems, and any efficiency gained from using plain tex is desired. I haven't checked in yet with the WeBWorK development crew though. Maybe they can green-light using less basic tex. – alex.jordan Mar 18 '14 at 0:30
  • Plain TeX may be marginally quicker to start up than latex but it is unlikely to be important but you are not using plain tex, you are using latex and loading amsart, so you are already absorbing the main extra startup time of latex, the filesystem access to load the class file, then you are not using any of the facilities of the file loaded. Plain Tex is not used in the code you have posted, it is just all latex. – David Carlisle Mar 18 '14 at 0:54
  • Thanks @DavidCarlisle. I'm not 100% sure yet what the WeBWorK experts will say about using elements of plain tex versus LaTeX (I've asked but only earlier today). I had whittled down a WeBWorK-produced .tex file to a MWE for posting here, so there was probably elements of amsart in use within what I cut. I'm still waiting to hear from the WeBWorK experts what they think about using more LaTeX over plain tex, but since what you see in the first table is the current WeBWorK output, I am hesitant to propose monumental changes to its code. – alex.jordan Mar 18 '14 at 3:45
  • OK use whichever commands you like but either way you are not using plain TeX. Plain TeX is a different format, latex does not load the sources of plan Tex nor call it at run time. – David Carlisle Mar 18 '14 at 9:30
2

I don't understand what gain you think to obtain in this way. I don't understand why the \halign templates are specified in that way.

Your \omit\hfil\multispan is wrong and \hidewidth is what you're looking for.

\documentclass{amsart}


\begin{document}


\centerline{%
  \vbox{
    \halign{%
      #\hfil&&\kern 1em #\hfil\cr
      \hfil \(x\)&\hfil \(y\)\cr
      \hfil \parbox[t]{4ex}{\hrulefill}&\hfil \parbox[t]{4ex}{\hrulefill}\cr
      \hfil \parbox[t]{4ex}{\hrulefill}&\hfil \parbox[t]{4ex}{\hrulefill}\cr
    }
  }%
}

\bigskip

\centerline{%
  \vbox{
    \halign{%
      #\hfil&&\kern 1em #\hfil\cr
      \multispan2\hidewidth caption\hidewidth\cr
      \hfil \(x\)&\hfil \(y\)\cr
      \hfil \parbox[t]{4ex}{\hrulefill}&\hfil \parbox[t]{4ex}{\hrulefill}\cr
      \hfil \parbox[t]{4ex}{\hrulefill}&\hfil \parbox[t]{4ex}{\hrulefill}\cr
    }
  }%
}

\bigskip

\centerline{%
  \vbox{
    \halign{%
      #\hfil&&\kern 1em #\hfil\cr
      \multispan{2}\hidewidth caption that is very long\hidewidth\cr
      \hfil \(x\)&\hfil \(y\)\cr
      \hfil \parbox[t]{4ex}{\hrulefill}&\hfil \parbox[t]{4ex}{\hrulefill}\cr
      \hfil \parbox[t]{4ex}{\hrulefill}&\hfil \parbox[t]{4ex}{\hrulefill}\cr
    }
  }%
}


\end{document}

enter image description here

  • Given the output you show I suspect you processed your file with LaTeX. The OP said he wanted to stick to plain TeX, so I'm not sure this counts:-) – David Carlisle Mar 18 '14 at 1:03
  • Thanks! I did process it with LaTeX. I'm trying to understand how WeBWorK processes raw input to produce the pdfs that students use. I intervened to grab the raw .tex file to play with, so that I would understand better what WeBWorK does to create it before I meddled with WeBWorK's algorithm for creating the .tex. I should have altered my local IDE to process it with plain tex for a more honest simulation. I'm awaiting to hear from the WeBWorK experts if plain tex is necessary---if not, great. Either way this may make its way into WeBWorK code. – alex.jordan Mar 18 '14 at 3:39
  • But what you see in the first table is the current raw .tex output from WeBWorK. I'm just trying to tweak it and insert captions with as little alteration as possible. If my proposed changes to WeBWorK code were accepted, they would be adopted by hundreds of institutions and hundreds of thousands of students. So a good philosophy is to change as little as possible. – alex.jordan Mar 18 '14 at 3:50
  • @alex.jordan What I see there is awful TeX code, to begin with. In any case, \multispan{2}\hidewidth ...\hidewidth is what you need. – egreg Mar 18 '14 at 7:35
  • I have the green light to use LaTeX freely in this project now---thanks for the help. – alex.jordan Mar 18 '14 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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