Graphics, Figures & TablesMinipage of table and figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
dyuxta
Posts: 1
Joined: Sat Sep 05, 2015 12:03 am

Minipage of table and figure

Post by dyuxta »

How do I make a minipage - to set a table and a figure side by side?

Code: Select all

\begin{table}[ht]
\begin{minipage}[b]{0.45\linewidth}
\centering
\begin{tabular}{ | l | r | r | r |}
    \hline
    Student & Hours/week & Grade \\ \hline \hline	
    Ada Lovelace & 2 & A \\ \hline
    Linus Thorvalds & 8 & A \\ \hline
    Bruce Willis & 12 & F \\ \hline
    Richard Stallman & 10 & B \\ \hline
    Grace Hopper & 12 & A \\ \hline
    Alan Turing & 8 & C \\ \hline
    Bill Gates & 6 & D \\ \hline
    Steve Jobs & 4 & E \\ \hline
   \end{tabular}
    \caption{Student Database}
    \label{table:student}
\end{minipage}
\end{table}

\begin{figure}[ht]
\begin{minipage}[b]{0.45\linewidth}
\centering
\includegraphics[width=40mm]{figures/studentdatabasegraph.png}
\caption{2-D scatterplot of the Student Database}
\label{ }
\end{minipage}
\end{figure}

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

Minipage of table and figure

Post by Johannes_B »

Hi and welcome,

tables usually have captions on top of them.

Code: Select all

\documentclass[demo]{article}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{booktabs}
\begin{document}
\begin{table}
	\begin{minipage}{0.5\linewidth}
		\caption{Student Database}
		\label{table:student}
		\centering
		\begin{tabular}{lrr}
			\toprule
			Student          & h/week & Grade \\
			\midrule
			Ada Lovelace     & 2      & A \\
			Linus Thorvalds  & 8      & A \\
			Bruce Willis     & 12     & F \\
			Richard Stallman & 10     & B \\
			Grace Hopper     & 12     & A \\
			Alan Turing      & 8      & C \\
			Bill Gates       & 6      & D \\
			Steve Jobs       & 4      & E \\
			\bottomrule
		\end{tabular}
	\end{minipage}\hfill
	\begin{minipage}{0.45\linewidth}
		\centering
		\includegraphics[width=40mm]{figures/studentdatabasegraph.png}
		\captionof{figure}{2-D scatterplot of the Student Database}
		\label{ }
	\end{minipage}
\end{table}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
RMR
Posts: 1
Joined: Wed Dec 09, 2020 4:58 pm

Minipage of table and figure

Post by RMR »

Adding a resizebox to the table lets you scale it as necessary
\usepackage{caption}
\usepackage{graphicx}
\usepackage{booktabs}

\begin{table}
	\begin{minipage}{0.4\linewidth}
		\caption{Caption }
		\label{tab:le}
		\centering
		\resizebox{\textwidth}{!}{%
		\begin{tabular}[width=\linewidth]{@{}lll@{}}
    \toprule
    \textbf{Student} & \textbf{week} & \textbf{grade} \\ 
    \midrule
    Ada Lovelace & 2 & A \\
			Linus Thorvalds & 8 & A \\
			Bruce Willis & 12 & F \\
			Richard Stallman & 10 & B \\
			Grace Hopper & 12 & A \\
			Alan Turing & 8 & C \\
			Bill Gates & 6 & D \\
			Steve Jobs & 4 & E \\
    \bottomrule
    \end{tabular}}
	\end{minipage}\hfill
	\begin{minipage}{0.6\linewidth}
		\centering
		\captionof{figure}{Caption_2}
		\label{figu:re}
		\includegraphics[width=0.8\textwidth]{Figs/Pair1.PNG}
	\end{minipage}
\end{table}
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Minipage of table and figure

Post by Ijon Tichy »

Adding a resizebox to the table lets you scale it as necessary
In the example Johannes has shown, scaling is not necessary.

Moreover, the standard tabular environment does not understand an optional argument [width=\linewidth]. Moreover, \resizebox not only scales the text (often in an ugly way), it also scales the thickness of the rules. You should avoid it. I would suggest to use a smaller font, if you need to make the tabular smaller.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply