Solución:
Una forma sencilla de hacerlo sería utilizar el array
paquete, especificando el ancho de la columna con m{...}
. Por ejemplo:
begin{tabular}{ m{4cm} m{1cm} }
... & ... \end{tabular}
le dará una columna de cuatro centímetros de largo y una columna de un centímetro de largo. En cada celda, el contenido se alineará verticalmente al centro. Sin embargo, tenga en cuenta que el contenido de la celda se alineará horizontalmente a la izquierda. Si también desea alinear todo el contenido de la celda hacia el centro en sentido horizontal, puede hacer algo como esto:
begin{tabular}{ >{centeringarraybackslash} m{4cm} >{centeringarraybackslash} m{4cm} }
... & ... \end{tabular}
El punto de arraybackslash
es volver \
a su significado original porque el centering
comando altera esto y posiblemente podría darle un noalign
error durante la compilación.
Si tiene varias columnas y no desea que su fuente se vea desordenada, puede definir nuevas columnas antes de su entorno tabular, por ejemplo:
newcolumntype{C}{ >{centeringarraybackslash} m{4cm} }
newcolumntype{D}{ >{centeringarraybackslash} m{1cm} }
begin{tabular}{ C D }
... & ... \end{tabular}
Hay mucha información útil sobre tablas en la guía wiki LaTeX, si desea explorar esto más a fondo.
documentclass{article}
usepackage[a4paper,vmargin=2cm,hmargin=1cm,showframe]{geometry}
usepackage[demo]{graphicx}
usepackage[table]{xcolor}
usepackage{array}
usepackage{longtable}
parindent=0pt
defcorrection#1{%
abovedisplayshortskip=#1baselineskiprelaxbelowdisplayshortskip=#1baselineskiprelax%
abovedisplayskip=#1baselineskiprelaxbelowdisplayskip=#1baselineskiprelax}
arrayrulewidth=1ptrelax
tabcolsep=5ptrelax
arrayrulecolor{red}
fboxsep=tabcolseprelax
fboxrule=arrayrulewidthrelax
newcolumntype{A}[2]{%
>{minipage{dimexpr#1linewidth-2tabcolsep-#2arrayrulewidthrelax}vspacetabcolsep}%
c<{vspacetabcolsependminipage}}
newenvironment{Table}[4]{%
longtable{%
|A{#1}{1.5}% for figure
|>{centering$displaystyle}A{#2}{1}<{$}% for inline equation
|>{correction{-1}strut[}A{#3}{1}<{]strut}% for displayed equation
|>{centering}A{#4}{1.5}% for text
|}hlineignorespaces}{%
endlongtableignorespacesafterend}
newcommand{dummy}{%
It is practically a big lie that LaTeX
makes you focus on the content without
bothering about the layout.}
newcommand{Row}{%
includegraphics[width=linewidth]{newton}&
frac{a+b}{a-b}=0&
int_a^b f(x), textrm{d}x=frac{b-a}{b+a}&
fcolorbox{cyan}{yellow}{parbox{dimexprlinewidth-2fboxsep-2fboxrulerelax}{dummy}}
tabularnewlinehline}
begin{document}
begin{Table}{0.25}{0.25}{0.25}{0.25}
Row
Row
end{Table}
defx{centering$displaystyleint_a^bf(x),textrm{d}x=frac{a-b}{a+b}$}
longtable{|A{0.2}{1.5}*2{|A{0.25}{1}}|A{0.3}{1.5}|}hline
x & x & multicolumn{2}{A{0.55}{1.5}|}{x} tabularnewlinehline
multicolumn{2}{|A{0.45}{1.5}|}{x} & x & xtabularnewlinehline
x & multicolumn{2}{A{0.5}{1}|}{x} & xtabularnewlinehline
multicolumn{4}{|A{1}{2}|}{x}tabularnewlinehline
endlongtable
end{document}
Poner un tabular en la celda de un tabular centra el contenido de la celda horizontal y verticalmente.
begin{tabular}{|l|c|c|}
hline
begin{tabular}{l}
text in cell 1
end{tabular} &
begin{tabular}{l}
first line of text in cell 2 \
second line of text in cell 2
end{tabular} &
begin{tabular}{l}
first line of text in cell 3 \
second line of text in cell 3 \
third line of text in cell 3 \
end{tabular}
\
hline
begin{tabular}{l}
first line of text in cell 4 \
second line of text in cell 4
end{tabular} &
begin{tabular}{l}
first line of text in cell 5 \
second line of text in cell 5 \
third line of text in cell 5 \
end{tabular} &
begin{tabular}{l}
first line of text in cell 6 \
second line of text in cell 6 \
end{tabular} \
hline
end{tabular}
da:
para que puedas definir una macro centered
newcommand{centered}[1]{begin{tabular}{l} #1 end{tabular}}
y utilícelo así:
%begin{tabular}{|l|c|c|} <- Old version of this answer
begin{tabular}{|@{}[email protected]{}|@{}[email protected]{}|@{}[email protected]{}|}
% This update now avoids double indentations and allows hlines
hline
centered{ text in cell 1 } &
centered{
first line of text in cell 2 \
second line of text in cell 2} &
centered{
first line of text in cell 3 \
second line of text in cell 3 \
third line of text in cell 3 \ } \
hline
centered{
first line of text in cell 4 \
second line of text in cell 4 } &
centered{
first line of text in cell 5 \
second line of text in cell 5 \
third line of text in cell 5 \ } &
centered{
first line of text in cell 6 \
second line of text in cell 6 \ } \
hline
end{tabular}