0

I have a hard time making a table that would have predefined dimensions (the whole page) and cells centered horizontally and vertically. I have found solutions for each of those problems individually,but they does not work together. Solutions that I have found so far took me to this point:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[czech]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}

\usepackage[total={17cm,25.7cm}, top=2cm, left=2cm, includefoot, bindingoffset=-0.63cm]{geometry} %\usepackage[twoside, hscale=0.88, vscale=0.88, bindingoffset=0cm]{geometry}

\usepackage{tikz} \usepackage{array} \usepackage{booktabs,adjustbox}

\newcommand{\finalcells}[2]{% \begingroup\sbox0{\begin{minipage}{3cm}\raggedright#1\end{minipage}}% \sbox2{\begin{minipage}{3cm}\raggedright#2\end{minipage}}% \xdef\finalheight{\the\dimexpr\ht0+\dp0+\smallskipamount\relax}% \xdef\finalheightB{\the\dimexpr\ht2+\dp2+\smallskipamount\relax}% \ifdim\finalheightB>\finalheight \global\let\finalheight\finalheightB \fi\endgroup \begin{minipage}[t][\finalheight][t]{3cm}\raggedright#1\end{minipage}& \begin{minipage}[t][\finalheight][t]{3cm}\raggedright#2\end{minipage}}

\begin{document}

{\setlength{\extrarowheight}{3.5 cm} %\setlength{\tabcolsep}{4.25cm}

\begin{tabular}{| m{8.5cm} | m{8.5cm} |}

\hline asdasd & • \ \hline • & • \ \hline • & • \ \hline • & • \ \hline • & • \ \hline • & • \ \hline \end{tabular} }

\end{document}

It creates the table witch predefined dimensions, but the text is not centered. The thing that I actually want is to make two-sided (playing) cards that would match after the printing. Thank for any advice.

  • Welcome to TeX.SE! See if use of \begin{tabular}{| >{\centering\arraybackslash}m{8.5cm} | >{\centering\arraybackslash}m{8.5cm} |} gives what you like to have. BTW, why you define table cells on so complicated way? – Zarko Oct 24 '20 at 00:43
  • @user227450 please have a look at the answer – js bibra Oct 24 '20 at 14:50

2 Answers2

1

It is not clear what you like to have. More empty space above/below cell contents? What should happen, if you have longer text in cells, for example if it is break in four lines?

I guess, that the following (much simpler) solution gives what you like to get:

\documentclass[12pt,a4paper]{article}
\usepackage[total={17cm,25.7cm},
            top=2cm, left=2cm,
            includefoot, bindingoffset=-0.63cm]{geometry}
\usepackage[czech]{babel}
\usepackage[T1]{fontenc}

\usepackage{array, booktabs} \usepackage[column=O]{cellspace} % for additiona vertical space above/below cells contets \setlength\cellspacetoplimit{22pt} \setlength\cellspacebottomlimit{22pt} \usepackage{adjustbox} \usepackage{lipsum}

\begin{document} \begin{tabular}{| >{\centering\arraybackslash}O{m{8.5cm}} | >{\centering\arraybackslash}O{m{8.5cm}} |} \hline asdasd & \lipsum[1][1-3] \ \hline • & • \ \hline • & • \ \hline • & • \ \hline \end{tabular} \end{document}

enter image description here

Zarko
  • 296,517
0

Your friend in such cases is the command

\rule[-5em]{0pt}{10em}

which adds an invisible rule above and below the contents of each cell -- dimensions as per choice

The pros an cons of various types of vertical and horizontal padding are discussed at many places on this site including --

Column and row padding in tables

The new P type of column gives the horizontal and vertical centering which you look for -- with \centering for horizontal centering and m{} giving the vertical centering in the command

\newcolumntype{P}[1]{>{\rule[-5em]{0pt}{10em}\centering\arraybackslash}m{#1\textwidth}}

The width of each column is defined as a percentage of the text width by simply entering P{0.4} thereby meaning the column will take up 40% of the text width

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[czech]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}

\usepackage[total={17cm,25.7cm}, top=2cm, left=2cm, includefoot, bindingoffset=-0.63cm]{geometry} %\usepackage[twoside, hscale=0.88, vscale=0.88, bindingoffset=0cm]{geometry}

\usepackage{tikz} \usepackage{array} \usepackage{booktabs,adjustbox}

% %\newcommand{\finalcells}[2]{% % \begingroup\sbox0{\begin{minipage}{3cm}\centering#1\end{minipage}}% % \sbox2{\begin{minipage}{3cm}\centering#2\end{minipage}}% % \xdef\finalheight{\the\dimexpr\ht0+\dp0+\smallskipamount\relax}% % \xdef\finalheightB{\the\dimexpr\ht2+\dp2+\smallskipamount\relax}% % \ifdim\finalheightB>\finalheight % \global\let\finalheight\finalheightB % \fi\endgroup % \begin{minipage}[t][\finalheight][t]{3cm}\centering#1\end{minipage}& % \begin{minipage}[t][\finalheight][t]{3cm}\centering#2\end{minipage}}

\newcolumntype{P}[1]{>{\rule[-5em]{0pt}{10em}\centering\arraybackslash}m{#1\textwidth}} \begin{document}

% {\setlength{\extrarowheight}{3.5 cm} %\setlength{\tabcolsep}{4.25cm}

    \begin{tabular}{| P{0.4} | P{0.4} |} 

        \hline
        asdasd  & • \\ 
        \hline 
        • & • \\ 
        \hline 
        • & • \\ 
        \hline 
        • & • \\ 
        \hline 
        • & • \\ 
        \hline 
        • & • \\ 
        \hline 
    \end{tabular}

% }

\end{document}

js bibra
  • 21,280