3

I have problems with vertically aligning content in my single row header table for an invoice template. Currently it looks like this: example What do I have to do to

  1. align the top fbox to the top of the right cell?
  2. align the bottom fbox to the bottom of the right cell?

    \documentclass[10pt,a4paper]{article}
    \usepackage[MeX]{polski}
    \usepackage[utf8]{inputenc}
    
    \setlength{\marginparwidth}{0pt}
    \setlength{\parindent}{0pt}
    
    \usepackage[
    top    = 1.50cm,
    bottom = 1.50cm,
    left   = 1.50cm,
    right  = 1.50cm]{geometry}
    
    \usepackage{tabularx}
    
    \pagestyle{empty}
    
    \renewcommand{\familydefault}{\sfdefault}
    
    \newcommand{\datasprzedazy}{3.03.2006}
    \newcommand{\terminplatnosci}{17.03.2006}
    \newcommand{\nrfaktury}{3/2006} 
    \newcommand{\netto}{1000.00} 
    \newcommand{\vat}{220.00}
    \newcommand{\brutto}{1220.00}
    \newcommand{\slownie}{jeden tysiąc dwieście dwadzieścia złotych}
    
    \begin{document}
    
    \renewcommand\arraystretch{1.3}
    \renewcommand\tabcolsep{0pt}
    
    \begin{tabularx}{\linewidth}{ X X }
        \begin{minipage}[t]{0.47\textwidth}
            \fbox
            {
                \parbox[t]{\textwidth}
                {
                    \begin{minipage}[t]{0.5\textwidth}
                        \begin{tabular}[t]{l l }
                        Company Name & Logo\\
                        Address & \\
                        Street & \\
                        Tax ID &\\
                        Other Info
                        \end{tabular}\par\medskip
                    \end{minipage}  
                }
            }
        \end{minipage}
    &
        \begin{minipage}[t]{0.47\textwidth}
            \framebox[\textwidth]{\textbf{Faktura VAT nr \nrfaktury}} \par
            \begin{tabular}{lr}
            Data sprzedaży: & \datasprzedazy \\
            Data wystawienia: & \datasprzedazy
            \end{tabular}
            \framebox[\textwidth]{\textbf{ORYGINAŁ}} \par
         \end{minipage}
    \end{tabularx}
    \end{document}
    
5

Some low level TeX programming makes the job easier: we set the left box (assuming it's the largest with respect to its vertical dimension) with \hrule at the top and at the bottom; the first is to set the box with no height, the last one is just for symmetry. More important is the last \hrule in the right hand box, that avoids TeX considering the depth of the last inner box.

The right hand box is set in a \vtop to \dp0, so it will have the same vertical dimension as the left hand box. Then we typeset the two boxes.

\documentclass[10pt,a4paper]{article}
\usepackage[MeX]{polski}
\usepackage[utf8]{inputenc}

\setlength{\parindent}{0pt}

\usepackage[
  top    = 1.50cm,
  bottom = 1.50cm,
  left   = 1.50cm,
  right  = 1.50cm,
]{geometry}

\usepackage{tabularx}

\pagestyle{empty}

\renewcommand{\familydefault}{\sfdefault}

\newcommand{\datasprzedazy}{3.03.2006}
\newcommand{\terminplatnosci}{17.03.2006}
\newcommand{\nrfaktury}{3/2006} 
\newcommand{\netto}{1000.00} 
\newcommand{\vat}{220.00}
\newcommand{\brutto}{1220.00}
\newcommand{\slownie}{jeden tysiąc dwieście dwadzieścia złotych}

\begin{document}

\renewcommand\arraystretch{1.3}
\renewcommand\tabcolsep{0pt}


\setbox0=\vtop{
  \hrule height 0pt
  \hbox{\fbox{%
    \begin{minipage}[t]{0.47\textwidth}
    \begin{tabular}[t]{ l l }
      Company Name & Logo\\
      Address & \\
      Street & \\
      Tax ID &\\
      Other Info
    \end{tabular}
    \end{minipage}%
  }}% end the \fbox and the \hbox
  \hrule height 0pt
  }% end the \vtop

\setbox2=\vtop to \dp0{
  \hrule height 0pt
  \hbox{\framebox[0.47\textwidth]{\textbf{Faktura VAT nr \nrfaktury}}}
  \vfill
  \hbox{\begin{tabular}{lr}
    Data sprzedaży: & \datasprzedazy \\
    Data wystawienia: & \datasprzedazy
  \end{tabular}}
  \vfill
  \hbox{\framebox[0.47\textwidth]{\textbf{ORYGINAŁ}}}
  \hrule height 0pt
  }

\leavevmode\box0\hfill\box2\par
\end{document}

enter image description here

  • Thank you. Can you recommend a good TeX book, please? – phil Sep 22 '13 at 12:57
  • @phil The TeXbook, of course, but also TeX by Topic that's available on CTAN and in TeX Live. – egreg Sep 22 '13 at 15:08
0

Certainly not a robust solution, but if your invoice template will always have the dimensions you have listed (no text wrapping, extra entries, etc..) then you could just set the right column as

\begin{minipage}[t]{0.47\textwidth}
    \vspace{-14.5pt}
    \framebox[\textwidth]{\textbf{Faktura VAT nr \nrfaktury}} \par

    \begin{tabular}{lr}
    Data sprzedaży: & \datasprzedazy \\
    Data wystawienia: & \datasprzedazy
    \end{tabular}

    \vspace{27pt}
    \framebox[\textwidth]{\textbf{ORYGINAŁ}} \par
 \end{minipage}

I will play with it a bit and see if I can come up with something that automatically does this for you.

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.