6

I would like to know how can I put two diagrams on the same like rather than one of the top and one at the bottom. which consumed too much space on the paper. Here are the codes for the figure which I used.

  \begin{figure}[!htb]\centering
     \frame{\includegraphics[width=10cm]{Data1}}
     \caption{Interpolation for Data 1}
  \label{Fig:Data1}
  \end{figure}

  \begin{figure}[!htb]\centering
     \frame{\includegraphics[width=10cm]{Data2}}
     \caption{Interpolation for Data 2}
  \label{Fig:Data2}
  \end{figure}
Sandra
  • 481
  • I think that is difficult since the width of the images are 10cm each, meaning it is wider than the page width, or are you using landscape? – rtzll Jan 09 '13 at 08:33
  • You have to make subfigures with the 'subfig' package. Please see the answer to (http://tex.stackexchange.com/questions/83664/inserting-subfigures) – TeXtnik Jan 09 '13 at 08:33
  • @ChristianR. - What width do you think I should put for both to fit on the same line? I have been working on two graph whereby the second is a replica of the first with shorten range and domain to give a clearer picture at certain spots. So I would like both to appear on the same line if possible. – Sandra Jan 09 '13 at 08:49
  • @zunbeltz - tried that as well but its not working. I even modified the width to 5cm each and still no luck. But I do receive the caption of both diagrams as (a) and (b). – Sandra Jan 09 '13 at 08:56

2 Answers2

6
\documentclass{article}
\usepackage[demo]{graphicx}% delete [demo] later
\begin{document}

\begin{figure}[!htb]\centering
   \begin{minipage}{0.49\textwidth}
     \frame{\includegraphics[width=\linewidth]{Data1}}
     \caption{Interpolation for Data 1}\label{Fig:Data1}
   \end{minipage}
   \begin {minipage}{0.49\textwidth}
     \frame{\includegraphics[width=\linewidth]{Data2}}
     \caption{Interpolation for Data 2}\label{Fig:Data2}
   \end{minipage}
\end{figure}

\end{document}

put them in one figure environment without an empty line between. The % is important here.

  • No it didn't work out. – Sandra Jan 09 '13 at 08:48
  • sure, 10cm +10cm is too wide for a line. Try it with width=0.49\textwidth –  Jan 09 '13 at 08:51
  • I just tried this and not sure why but this didn't workout. – Sandra Jan 09 '13 at 09:06
  • didn't workout is not a very useful description of your problem ... –  Jan 09 '13 at 09:11
  • sorry! What I meant is my diagram is still like the usual one of top and one at the bottom even applying the width to 0.49. – Sandra Jan 09 '13 at 09:13
  • sorry, you are right, I forgot the minipages in the example. See edited code. –  Jan 09 '13 at 09:19
  • There is an error when compiled based on "\begin{minipage}{width=0.49\textwidth}" and the error message says "Missing number, treated as zero". Any idea why is this? – Sandra Jan 09 '13 at 09:26
  • @Herbert I think you have to delete width= in the minipage environment, meaning just use: \begin{minipage}{0.49\textwidth} – rtzll Jan 09 '13 at 09:26
  • @Sandra: uuuh, this seems not be my day ... :-) See my complete example, which runs without an error –  Jan 09 '13 at 09:29
  • @Herbert: BINGO... You got it! At 10cm, my graph appear next to each other well. I learn new function about minipage today. Thanks Herbert. – Sandra Jan 09 '13 at 09:33
  • @Herbert: Do you happen to know what feature I can use to reduce the size of the caption text? I use "small caption" but after using minipage, it seem become normal size again. – Sandra Jan 09 '13 at 09:36
  • you should use the package caption it has a lot of useful options for setting a caption. However, it is also possible to put the caption also in an own minipage of a smaller width. But I would prefer package caption See its documentation. –  Jan 09 '13 at 09:47
  • @Herbert - Great! Thanks. I will look this up. – Sandra Jan 09 '13 at 09:56
  • @Herbert Shouldn't there be a % sign at the end of the first minipage as mentioned in your answer? – Benedikt Bauer Jan 09 '13 at 14:29
  • @BenediktBauer: I use it always, makes it easier to see where a minipage ends and the other begins. But it is not important. –  Jan 09 '13 at 14:36
  • @Herbert I thought it must be there in this case to eliminate the whitespace between the two minipages if you want them to have .5\linewidth. In your case (.49\linewidth) it should OK without it. And as you write in your answer "The % is important here" and then there isn't a % sign in your code may be confusing. – Benedikt Bauer Jan 09 '13 at 14:41
  • no. She uses \centering so the space doesn't hurt. For two minipages of 0.49\textwidth or smaller I prefer ...\end{minpage}\hfill% for the end of the first minipage and no centering –  Jan 09 '13 at 14:44
3

I changed the width to fit it on a page, the total width you can use is dependend on the documentclass.

I would use subfigures as follows (for the image I used the tex.sx logo):

Code

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{5cm}            
\frame{\includegraphics[width=5cm]{Data1}}
\caption{Interpolation for Data 1}
\label{Fig:Data1}
\end{subfigure}
%
\hspace{1cm}
%
\begin{subfigure}[b]{5cm}
\centering
\frame{\includegraphics[width=5cm]{Data2}}
\caption{Interpolation for Data 2}
\label{Fig:Data2}
\end{subfigure}
\caption{Interpolation}\label{fig:TOF}
\end{figure}
\end{document}

Output

image

rtzll
  • 5,531
  • I tried this and my graph become rather small. Do you think it is possible to make it big while ignoring the margins of the paper? And eventhough it works, the subcaption package clash with my small caption package. So when I removed the small caption package, then it works but the caption become like normal size text. – Sandra Jan 09 '13 at 09:04
  • @Sandra I'm not familiar with the small caption package so I can't help you there, but with the page width you could use the ¸geometry package, which allows you to set specific page margins. – rtzll Jan 09 '13 at 09:10
  • Thanks for your assistance though. I may have to use your method if other methods didn't workout even if the graph is rather small to be read considering there are three functions in one graph. – Sandra Jan 09 '13 at 09:15
  • @Sandra Maybe you can tweak it a bit also using the height argument, as so: [width=5cm,height=5cm]. I'd say try various values and see what is closest to what you want. – rtzll Jan 09 '13 at 09:19
  • Thanks. The function's lines and the points on the x axis is still not very clear. Not sure if it is Mathematica faults as my graphs were done using Mathematica. The previous 10cm which I used is not very clear too but still can be read when printed using laser printer. When adjust to 5cm width and height, the lines when printed, blurr out. – Sandra Jan 09 '13 at 09:30
  • How do I get rid of those annoying border lines around the graphics? For my paper, I neither need them nor want them. – Forklift17 Jun 08 '17 at 21:22