Page LayoutSet the height of an expression

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
LaTeX
Posts: 11
Joined: Sun Sep 27, 2015 11:04 am

Set the height of an expression

Post by LaTeX »

Hello,

I want to set two pictures on my titlepage beside each other, one with text above and below it and I want the other picture to have precisely the same height. I tried the following code, but apparently it doesn't work properly:

Code: Select all

\newlength{\height_1}
\settoheight{\height_1}{$\overset{\text{Text over picture 1}}{\underset{\text{Text below picture 1}}{\vcenter{\hbox{\includegraphics[height=5cm]{Picture_1.eps}}}}}$}

\[
\overset{\text{Text over picture 1}}{\underset{\text{Text below picture 1}}{\vcenter{\hbox{\includegraphics[height=5cm]{Picture_1.eps}}}}} \qquad \vcenter{\hbox{\includegraphics[height=\height_1]{Picture_2.eps}}}}
\]
Thanks!

Recommended reading 2024:

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

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

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Set the height of an expression

Post by Johannes_B »

Please provide a minimal working example. I bet your are trying to do something pretty simple, but using the wrong approach to achieve it. Using math and overset seems to be a quite confused way to put boxes.

Hint: Package mwe provides some sample pictures you can use.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
LaTeX
Posts: 11
Joined: Sun Sep 27, 2015 11:04 am

Set the height of an expression

Post by LaTeX »

Thanks already for your answer, a minimal working example of my current code is

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{graphicx}

\begin{document}

\newlength{\Height}
\settoheight{\Height}{$\overset{\text{Text over picture 1}}{\underset{\text{Text below picture 1}}{\vcenter{\hbox{\includegraphics[height=5cm]{Picture_1.jpg}}}}}$}

\title{Minimal working example\\\vspace{\baselineskip}
\[ \overset{\text{Text over picture 1}}{\underset{\text{Text below picture 1}}{\vcenter{\hbox{\includegraphics[height=5cm]{Picture_1.jpg}}}}} \qquad \vcenter{\hbox{\includegraphics[height=\Height]{Picture_2.jpg}}} \]}

\author{Author}

\maketitle

\end{document}
I guess there is a better way to code this, does somebody have a recommendation? Thanks!
Last edited by Stefan Kottwitz on Sun Sep 27, 2015 5:16 pm, edited 2 times in total.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Set the height of an expression

Post by cgnieder »

\newlength{\height_1} can't work because macro names cannot contain non-letters such as underscores or numbers.

Instead of \\\vspace{\baselineskip} you either want only \vspace{\baselineskip} (but you may need to ensure that the paragraph ends before) or \\[\baselineskip].

I can't test the following since I don't have the picture files but instead of abusing math commands I'd use (nested) {tabular}s:

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{graphicx}

\newlength\Height
\settoheight\Height{%
  \begin{tabular}{c}
    Text over picture 1 \\
    \includegraphics[height=5cm]{Picture_1.jpg} \\
    Text below picture 1
  \end{tabular}%
}

\title{
  Minimal working example \\[\baselineskip]
  \begin{tabular}{cc}
    \begin{tabular}{c}
      Text over picture 1 \\
      \includegraphics[height=5cm]{Picture_1.jpg} \\
      Text below picture 1
    \end{tabular} &
    \includegraphics[height=\Height]{Picture_2.jpg}
  \end{tabular}
}

\author{Author}

\begin{document}

\maketitle

\end{document}
Regards
site moderator & package author
LaTeX
Posts: 11
Joined: Sun Sep 27, 2015 11:04 am

Re: Set the height of an expression

Post by LaTeX »

Great, thanks!
LaTeX
Posts: 11
Joined: Sun Sep 27, 2015 11:04 am

Set the height of an expression

Post by LaTeX »

I just tried your solution (which looks really nice), but height is still not correct. I modified it such that the pictures are vertically centered and such that the two pictures including the text are horizontally centered. This is the minimal working example (with "example-image" it should also work at your computer):

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{graphicx}


\begin{document}

\newlength\Height
\settoheight\Height{%
	\begin{tabular}{c}
		Text over picture 1 \\
		$\vcenter{\hbox{\includegraphics[height=2.5cm]{example-image}}}$ \\
		Text below picture 1
	\end{tabular}%
}

\begin{center}
\begin{tabular}{cc}
	\begin{tabular}{c}
		Text over picture 1 \\
		$\vcenter{\hbox{\includegraphics[height=2.5cm]{example-image}}}$ \\
		Text below picture 1
	\end{tabular} &
	$\vcenter{\hbox{\includegraphics[height=\Height]{example-image}}}$
\end{tabular}
\end{center}

\end{document}
Does anybody has an idea?
Last edited by LaTeX on Tue Sep 29, 2015 8:00 pm, edited 1 time in total.
LaTeX
Posts: 11
Joined: Sun Sep 27, 2015 11:04 am

Set the height of an expression

Post by LaTeX »

Edit:

The function \settototalheight{}{} from the package "calc" works perfectly:

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{calc}


\begin{document}

\newlength{\Height}
\settototalheight{\Height}{\hbox{%
	\begin{tabular}{c}
		\small Text 1 \\
		\small Text 2 \\
		$\vcenter{\hbox{\includegraphics[height=2cm]{example-image}}}$ \\
		\small Text 3 \\
		\small Text 4
	\end{tabular}%
}
}

\begin{center}
\begin{tabular}{cc}
	\begin{tabular}{c}
		\small Text 1 \\
		\small Text 2 \\
		$\vcenter{\hbox{\includegraphics[height=2cm]{example-image}}}$ \\
		\small Text 3 \\
		\small Text 4
	\end{tabular} &
	$\vcenter{\hbox{\includegraphics[height=\Height]{example-image}}}$
\end{tabular}
\end{center}

\end{document}
Thanks for your answers!
Post Reply