0

I need to set minimal table (one-row table) height, and valign content inside it. For this prupose i wrap tabular in parbox in tabular i have correct valign, and parbox gives me min height.

My question is - how to valign table in parbox (or to make it with me minipage, but then - how to make a min height)?

Here is the example code (it's the same in prev question :) ) : how to valign table (here it's in the header)

\documentclass{book}
\usepackage{fancybox,fancyhdr}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames]{xcolor}

\usepackage[left=72pt,right=72pt,
    headheight=124pt,
    top=\dimexpr124pt+\headsep\relax,% <- added
    textheight =540pt
    ]{geometry}
\usepackage{array}


\newcolumntype{L}[2]{>{\raggedright\arraybackslash}{#2}{#1}}

\fancyhf{}
\fancyhead[C]{%
  \sbox{0}{\parbox{\textwidth}{\begin{tabular}{@{}L{\textwidth}{p}@{}}Non-disclosure agreement (NDA)\end{tabular}}}%
  \ifdim\dimexpr\ht0+\dp0<124pt \dp0\dimexpr124pt-\ht0\fi
  \makebox{\usebox{0}}%
}

\usepackage{lipsum}
\usepackage{showframe}
\begin{document}
\pagestyle{fancy}
\lipsum
\end{document}

Due to comments: common task is to make a table with one raw and several columns and valign-halign and fixed minimal height. In my example i use only one column to make task less complicated

  • your question isn't that clear, why do you need the parbox at all? it does not seem to be doing anything, also a one-column, one row tabular isn't doing anything useful either. Could you state what is the intended effect of the code? – David Carlisle Apr 27 '17 at 10:04
  • @DavidCarlisle Parbox sets the height (minmal) to 124. all "unuseful" code - is due to automatic generation. I generate all automaticly - so this one-cell table is a particular case. I have more complicated examples, but it will be the same issue ) In common i need a table (one-raw) with the fixed minimal height and valign. – Mira Apr 27 '17 at 10:09
  • No, parbox does have an optional argument to set its height but you are not using that. I honestly can not guess what this code is intended to do, not only the parbox and tabular (which does not do anything very much other than box the text Non-disclosure agreement) but also the setting of the depth of the box afterwards. perhaps you just want \fancyhead[C]{\rule{0pt}{124pt}Non-disclosure agreement (NDA)} but I really can not guess. – David Carlisle Apr 27 '17 at 10:14
  • @DavidCarlisle usually there is a two or three columns. (In the example - only one cell with the small text). In each cell there must be valign and halign and fixed minimal height. So just \rule can't make it. – Mira Apr 27 '17 at 10:19
  • Min height in parbox - works ok, i don't know how ))) i'm not good in latex, i just found an example here, and make the same - it works. May be there is a better decision. But i don't know it. – Mira Apr 27 '17 at 10:25
1

Here is a simpler solution.

\documentclass{book}
\usepackage{fancybox,fancyhdr}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames]{xcolor}

\usepackage[left=72pt,right=72pt,
    headheight=124pt,
    top=\dimexpr124pt+\headsep\relax,% <- added
    textheight =540pt
    ]{geometry}
\usepackage{array}


\newcolumntype{L}[2]{>{\raggedright\arraybackslash}{#2}{#1}}

\fancyhf{}
\fancyhead[C]{%
  %\raisebox{\dimexpr\headheight-\height}[\headheight][0pt]% top alignment
  %\raisebox{0pt}[0.5\headheight][0.5\headheight]% middle alignment
  \raisebox{\depth}[\headheight][0pt]% bottom alignment
  {\begin{tabular}{@{}L{\textwidth}{p}@{}}
  Non-disclosure agreement (NDA)\\
  %a\\b\\c\\d\\e\\f\\g\\h\\i\\j\\k\\l
  \end{tabular}}%
}

\usepackage{lipsum}
\usepackage{showframe}
\begin{document}
\pagestyle{fancy}
\lipsum
\end{document}
| improve this answer | |
  • So there is no vertical alignment in your answer, i need vertical alignment by middle or bottom – Mira Apr 28 '17 at 0:49
  • bottom for example. When i put {\begin{tabular}{@{}L{\textwidth}{b}@{}} it doesn't works – Mira Apr 28 '17 at 3:28
  • [b] should go first. Anyway, \raisebox moves the baseline where it belongs. – John Kormylo Apr 28 '17 at 3:47

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.