1

I am trying to create a page length box around a centrally placed text with a caption beneath it. The central text is one line formula. The box should fill all available space except for at the bottom, where a bottom-aligned caption restricts it. I have scoured answers like those mentioned here and here, but being a beginner, failed to assimilate those into a solution (the problem being the cited answers don't deal with center alignment and captioning). How to obtain the layout shown below?

%Some code that generates a malformed output
\documentclass{scrartcl}
\usepackage{capt-of}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}

\begin{document} % dummy text

\par\noindent \tikz[overlay,remember picture]\coordinate (image-start); \par \hfill \vfill $1+2=3$ \vfill \null\hfill \tikz [overlay,remember picture] \draw (0,0) rectangle ([yshift=\ht\strutbox-\fboxsep]image-start); \hfill Caption\hfill \null \newpage \end{document}

lineage
  • 135
  • Welcome to TeX.SE. As you mention yourself this is essentially a duplicate of https://tex.stackexchange.com/questions/12125/stretching-a-framebox-over-the-whole-page. I would recommend https://tex.stackexchange.com/a/213292/ as the easiest of the four answers. I'll vote to close as a duplicate now, but if you want you can add your failed attempt (using any of the answers of the other question) to your own question here with the error message or incorrect output that you get, if it is indeed a different problem then the question will probably stay open or be reopened. – Marijn Mar 22 '21 at 10:21
  • 1
  • @Marijn thnx! I had indeed looked at https://tex.stackexchange.com/a/12128 but couldn't modify it to suit my needs. I have included my attempt in the answer now. I know you may be busy but I would really appreciate it if you could provide an answer...thanks again! – lineage Mar 22 '21 at 10:33
  • I just tried it, to make it work you need to 1. remove the empty line after %dummy text, 2. remove the \par before \noindent, 3. change the line with the caption to \par\centering Caption, and optionally 4. add \centering before the equation. – Marijn Mar 22 '21 at 11:22
  • 1
    For the other answer in the duplicate: `\documentclass{scrartcl} \usepackage[breakable]{tcolorbox} \newtcolorbox{stretchbox}[1][]{ height=0.97\textheight, valign=center, sharp corners, colback=white, #1}

    \begin{document} \begin{stretchbox} \centering$1+2=3$ \end{stretchbox} \centering Caption \end{document}also works but there you need to manually set the height (here:0.97\textheight`).

    – Marijn Mar 22 '21 at 11:30

2 Answers2

2

I started from the solution given here: https://tex.stackexchange.com/a/12128. The first \par is required if you want to omit a blank line before \frameeq

MWE

\documentclass{scrartcl}
\usepackage{tikz}
\usepackage{lipsum}

\newcommand{\frameeq}[2]{% \par\noindent\tikz[overlay,remember picture]\coordinate (image-start); \vfill \null\hfill \tikz [overlay,remember picture] \draw (0,0) rectangle ([yshift=\ht\strutbox-\fboxsep]image-start) node[midway] {#2}; \vspace{1ex}

{\centering #1\par} }

\begin{document}

\lipsum[1]

\frameeq{Caption here}{$2+2=5$}

\clearpage

\lipsum[1-3] \frameeq{Caption here}{$2+2=5$}

\end{document}

Output

enter image description here

Ivan
  • 4,368
0

The main change here is the use of \makebox to center text.

\documentclass{scrartcl}
\usepackage{capt-of}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}

\begin{document} % dummy text \par\noindent \tikz[overlay,remember picture]{\coordinate (image-start);} \par \vfill \noindent\makebox[\linewidth]{$1+2=3$}\par \vfill \null\hfill \tikz [overlay,remember picture]{\draw (0,0) rectangle ([yshift=\ht\strutbox-\fboxsep]image-start);} \par\noindent \makebox[\linewidth]{Caption} \newpage \end{document}

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120