[Tex/LaTex] Vertical alignment in tabular with fbox

boxestablesvertical alignment

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}
    

Best Answer

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