Graphics, Figures & TablesFigure alignment in table cell

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Figure alignment in table cell

Post by yoyoimut »

How to have a vertically centered image in a cell?

Is it possible to use \depth or \totalheight or other to adjust vertical alignment of the image exactly?

Related to: Figures in tables

Thank you in advance.


Yuko

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Figure alignment in table cell

Post by gmedina »

The suggestion of this other thread might be useful here too.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Figure alignment in table cell

Post by yoyoimut »

By doing many trials and errors, I found the exact (hopely :lol: ) method to vertically center an image in a cell.

Just enclose the image in a minipage.
Make sure you set the outer and inner vertical alignment option of minipage to c (center). Adjust the height and width of the minipage until they suit your need.

The following is my output. I have also checked the dimension using pdf-xchange viewer tools.
IMAGETABLE.jpg
IMAGETABLE.jpg (57.42 KiB) Viewed 2556 times

Here is the minimal code:

Code: Select all

\documentclass{book}
\usepackage{graphicx,array}

\begin{document}
\begin{tabular}{|>{\begin{minipage}[c][7cm][c]{6cm}\centering}m{6cm}<{\end{minipage}}|c|}\hline
\fbox{\includegraphics[height=4.5cm]{sample}} & sample.eps\\\hline
\rule{4cm}{4cm} & rule of 4cm by 4cm\\\hline
\end{tabular}
\end{document}

The image cannot be attached to this post because this site blocks eps type.


Thank myself.


regards,


Yuko
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Figure alignment in table cell

Post by yoyoimut »

This is my last modification.

Let me know if there is any other better way.

Code: Select all

\documentclass[a4paper]{article}
\usepackage{array,longtable,calc,xcolor,graphicx}
\usepackage[margin=2cm]{geometry}
\newcounter{SET}
\renewcommand{\theSET}{\stepcounter{SET}\arabic{SET}.}
\newcolumntype{X}[2]{>{\begin{minipage}[c][#1][c]{#2\textwidth}\begin{center}\arraybackslash}m{#2\textwidth}<{\end{center}\end{minipage}}}

\newenvironment{MyFancyTable}[4][10cm]
{\begin{longtable}{|>{\fbox{\theSET}\arraybackslash}X{#1}{#2}|*{2}{X{#1}{#4}|}}\hline\ignorespaces}
{\end{longtable}}



\setlength{\fboxsep}{0.1pt}
\setlength{\fboxrule}{0.05pt}

\begin{document}
\begin{MyFancyTable}[7cm]{0.05}{0.6}{0.35}
%==========================================================
&
\fbox{\color{cyan}\rule{\linewidth-2\fboxsep}{5cm}}
&
\fbox{Function $f(x)=x^2-1$.}
\\\hline
%==========================================================
&
\fbox{\scalebox{1.2}{$\displaystyle\int_a^bf(x)\,dx=F(b)-F(a)$}}
&
\fbox{\parbox{\linewidth-2\fboxsep}{Function $f(x)=x^2-1$ and $g(x)=f(x-1)$.}}
\\\hline
%==========================================================
&
\fbox{\color{cyan}\rule{\linewidth-2\fboxsep}{5cm}}
&
\fbox{Function $f(x)=x^2-1$.}
\\\hline
%==========================================================
&
\fbox{\scalebox{1.2}{$\displaystyle\int_a^bf(x)\,dx=F(b)-F(a)$}}
&
\fbox{\parbox{\linewidth-2\fboxsep}{Function $f(x)=x^2-1$ and $g(x)=f(x-1)$.}}
\\\hline
%==========================================================
&
\fbox{\color{cyan}\rule{\linewidth-2\fboxsep}{5cm}}
&
\fbox{Function $f(x)=x^2-1$.}
\\\hline
%==========================================================
&
\fbox{\scalebox{1.2}{$\displaystyle\int_a^bf(x)\,dx=F(b)-F(a)$}}
&
\fbox{\parbox{\linewidth-2\fboxsep}{Function $f(x)=x^2-1$ and $g(x)=f(x-1)$.}}
\\\hline
\end{MyFancyTable}
\end{document}


Thank you.
Post Reply