Information and discussion about graphics, figures & tables in LaTeX documents.
dyuxta
Posts: 1 Joined: Sat Sep 05, 2015 12:03 am
Post
by dyuxta » Sat Sep 05, 2015 12:05 am
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}
NEW: TikZ book now 40% off at Amazon.com for a short time.
Johannes_B
Site Moderator
Posts: 4182 Joined: Thu Nov 01, 2012 4:08 pm
Post
by Johannes_B » Sat Sep 05, 2015 1:19 pm
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
Post
by RMR » Wed Dec 09, 2020 5:32 pm
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}
Ijon Tichy
Posts: 640 Joined: Mon Dec 24, 2018 10:12 am
Post
by Ijon Tichy » Wed Dec 09, 2020 6:02 pm
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.