Graphics, Figures & TablesBox diagrams using tabular

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
wicko3
Posts: 4
Joined: Wed Jan 28, 2009 7:03 pm

Box diagrams using tabular

Post by wicko3 »

Hello,

I want to draw a diagram, composed of boxes and text, using the longtable package. (Perhaps this is a bad idea in the first place, but unless it's really impossible, I'd like to stick with this approach.)

Here is my package, called 'ribbonprooftest.sty', that I have written to do this:

Code: Select all

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ribbonproof}[2011/02/26 Presenting ribbon proofs.]

\RequirePackage{array}
\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{R}{>{$}r<{$}}
\RequirePackage{longtable}


\newlength\thickness
\setlength\thickness{1mm}

\newlength\tickheight
\setlength\tickheight{2mm}

\newlength{\tmplength}

\newcommand{\openribbon}[1]{%
\vrule height0mm depth\tickheight width\thickness%
\hspace{-\thickness}%
\vrule height\thickness depth0mm width#1%
\hspace{-\thickness}%
\vrule height0mm depth\tickheight width\thickness%
}
 
\newcommand{\closeribbon}[1]{%
\raisebox{\thickness}{\vrule height\tickheight depth0mm width\thickness}%
\hspace{-\thickness}%
\vrule height\thickness depth0mm width#1%
\hspace{-\thickness}%
\raisebox{\thickness}{\vrule height\tickheight depth0mm width\thickness}%
}

\newcommand{\retractribbon}[3]{%
\setlength\tmplength{#1}\addtolength\tmplength{\thickness}%
\raisebox{\thickness}{\vrule height\tickheight depth0mm width\thickness}%
\hspace{-\thickness}%
\vrule height\thickness width\tmplength depth0mm%
\hspace{-\thickness}%
\vrule height0mm depth\tickheight width\thickness%
\hspace{-\thickness}%
\hspace{#3}%
\hspace{-\thickness}%
\vrule height0mm depth\tickheight width\thickness%
\hspace{-\thickness}%
\setlength\tmplength{#2}\addtolength\tmplength{\thickness}%
\vrule height\thickness width\tmplength depth0mm%
\hspace{-\thickness}%
\raisebox{\thickness}{\vrule height\tickheight depth0mm width\thickness}%
}

\newcommand{\ribbon}[2]{% 
\setlength{\tmplength}{#1}%
\addtolength{\tmplength}{-2\thickness}%
\vrule width\thickness%
\hbox to \tmplength{\hspace{1mm}{#2}}%
\vrule width\thickness%
}

\newenvironment{ribbonproof}{%
\begin{longtable}[l]{L}
}{\end{longtable}}
Here is a file that tests the 'ribbonprooftest.sty' package:

Code: Select all

\documentclass[12pt,a4paper]{article}

\usepackage{ribbonprooftest}

\title{Test document}
\date{\today}

\begin{document}

\maketitle

\begin{ribbonproof}
\hspace{50mm} \hspace{4mm} \openribbon{30mm} \\
\openribbon{50mm} \hspace{4mm} \ribbon{30mm}{\parbox[t]{23mm}{Hello, this is a long piece of text.}}\\
\ribbon{50mm}{\parbox[t]{42mm}{Some more text, still rather long.}} \hspace{4mm} \ribbon{30mm}{} \\
\retractribbon{28mm}{0mm}{22mm} \hspace{4mm} \ribbon{30mm}{\parbox[t]{20mm}{And even more text!}}\\
\hspace{28mm}\ribbon{22mm}{\mbox{Text.}} \hspace{4mm} \closeribbon{30mm}\\
\openribbon{24mm}\hspace{4mm}\closeribbon{22mm} \\
\ribbon{24mm}{\mbox{Bye bye.}} \\
\end{ribbonproof}
\end{document} 
Here is a picture of the output:
ribbonproof_screenshot2.png
ribbonproof_screenshot2.png (21.73 KiB) Viewed 1182 times
Here is an annotated version of the same output, which shows where the row-breaks in the table are:
ribbonproof_screenshot1.png
ribbonproof_screenshot1.png (24.34 KiB) Viewed 1182 times
My question is: how can I remove the ugly gaps in my table, and make the components of each box touch each other? It seems like one should just need to add a bit of vertical glue in the right places, and make some of the rules a bit more stretchy, but I can't get it to work.

Any help or advice would be much appreciated. Many thanks.

John

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply