105 Comments

  1. Donald

    I was wondering if you had any tips on the creation of tables in LaTeX? This seems to be the most frustrating (to me) task. Ideally, I’d like a GUI table generator that converts the table into LaTeX.

    In any event, great blog!

    • Danny

      You might want to have a look at LyX. I use it to create all my tables and then paste the generated code into my Latex document.

      :).

    • Kevin

      I use a macro called calc2latex (converts tables form OpenOffice into latex output), works great! There’s one for Excel called xls2latex. Google them, follow the instructions and let the macros make the tables for you!

  2. Miguel Angel

    PLLEEEEASE help me:
    I would like to create a table in Latex and add it a note at the end of the table and the source where I got that table from. How can I add those lines of text at the end of the table?
    Thanks,
    Miguel

  3. Miguel Angel

    Hi Thomas,
    This is how I would like my table to look in Latex (for example):

    Table 1. This is my table title
    _____________________________
    1970 2000
    _____________________________

    GDP 3.5 5.4
    Inflation 2.0 4.1
    _____________________________
    Note: this values are not true.
    Source: World Bank (2003).

    I don’t have problems with citing inside the table. That works fine. But my problem is how to add the note and the source at the end of the table. I’ve tried different options, nothing works (i.e., minipage) and it looks horrible. I wonder if there is an automatic option to do that. Double caption wouldn’t work because there would be two “Table #”, I gather.

    What do you think?

    Miguel

  4. You might want to try using the table itself to hold the note and source. Try this:

    \begin{table}[ht]
        \begin{minipage}[b]{0.48\linewidth}
            \caption{Table 1. This is my table title}
            \centering
            \begin{tabular}{lcc}
                \hline
                &1970&2000\\
                \hline
                GDP&3.5&5.4\\
                Inflation&2.0&4.1\\
                \hline
                \multicolumn{3}{l}{Note: this values are not true.}\\
                \multicolumn{3}{l}{Source: World Bank (2003).}\\
            \end{tabular}
        \end{minipage}
        \hspace{0.5cm}
        \begin{minipage}[b]{0.48\linewidth}
            \caption{Table 1. This is my table title}
            \centering
            \begin{tabular}{lcc}
                \hline
                &1970&2000\\
                \hline
                GDP&3.5&5.4\\
                Inflation&2.0&4.1\\
                \hline
                \multicolumn{3}{l}{Note: this values are not true.}\\
                \multicolumn{3}{l}{Source: World Bank (2003).}\\
            \end{tabular}
        \end{minipage}
    \end{table}

    If you need vertical lines to separate cells, instead of the horizontal bar in the column-number defining tabular-environment option, you can use \vline
    Example:

    \vline&Inflation&\vline&2.0&\vline&4.1&\vline\\

    It’s a lot more to type, but this way you can omit the vertical lines around the note and source.

  5. Amir

    Ok, after some tries I could solve it myself. Here is the solution:

    \begin{table}[h]
      \begin{minipage}{0.45\textwidth}
      \centering
        \includegraphics[width=\textwidth]{fig1}
        \caption{caption fig1}
        \label{fig:fig1}
      \end{minipage}
      ~\hfill~
      \begin{minipage}{0.45\textwidth}
      \centering
        \begin{tabular}{|c|c|c|}
          moin & moin & moin\\
        \end{tabular}
        \caption{caption tab1}
        \label{tab:tab1}
    \end{minipage}
    \end{table}

    Thanks,
    Amir

  6. Winkelwagen

    To all those with difficulties making tables:

    If you’re comfortable with a program like OpenOffice.org Calc or Excel or whatever, you can use that program to make your tables.
    If you Google for “Excel table macro Latex” or something like that, you can find a macro to convert the table to a LaTeX table.

    AFAIK Excel2Latex is also usable for this kind of conversions.

  7. tom

    @ashokg

    This is not that easy actually. You can try the minipage-command, by using this Latex-source stab it worked perfectly well for me:

    \begin{figure}
      \centering
        \begin{minipage}[t]{0.58\linewidth}
          \includegraphics[width=1\linewidth]{figure-file}
        \end{minipage}\hfill
        \begin{minipage}[b]{0.38\linewidth}
          \caption{Whatever caption-text you want.\label{fig:caption}}
        \end{minipage}
    \end{figure}

    The most important thing here is the bottom-alignment of the right-hand side “minipage” ([b]). The linewidth of the figure is 1 in order to use the complete width provided by the “minipage”.

    Cheers,
    Tom.

  8. David

    Hey

    For some reason, I can’t get the minipage environment to place my tables side-by-side. Here’s the source:

    \begin{table}[h]
    \begin{minipage}[b]{2.25in}
    \centering
    \caption{}
    \begin{tabular}{@{}|l|c|c|}
    \hline
    & \hearts & $\lnot$\hearts\\
    & (0.2) & (0.8)\\
    \hline
    $A$ & &\\ fold hand & $-\$78$ & $-\$78$\\
    \hline
    $B$ & &\\ call raise & $+\$x$ & $-\$228$\\
    \hline
    \end{tabular}
    \label{table3}
    \end{minipage}
    \begin{minipage}[b]{2.25in}
    \centering
    \caption{}
    \begin{tabular}{@{}|l|c|c|}
    \hline
    & \hearts & $\lnot$\hearts\\
    & (0.2) & (0.8)\\
    \hline
    $A$ & &\\ fold hand & $-\$y$ & $-\$y$\\
    \hline
    $B$ & &\\ call raise & $+\$231$ & $-\$228$\\
    \hline
    \end{tabular}
    \label{table4}
    \end{minipage}
    \end{table}

    Any ideas why this won’t work? Thanks.

  9. tom

    @David

    Just remove the space between the two minipage-environments and the tables are placed side-by-side, as long as there is enough space vertically. If you want some space between, you can comment the empty line out

    ...
    \end{minipage}
    %
    \begin{minipage}
    ...

    Tom.

  10. David

    Miguel (or anyone else wondering about this)

    I’ve placed additional text at the bottom of my tables using a custom command I call ‘\capbot’ (caption bottom)

    \newcommand{\capbot}[1]{%
    	\vspace{8pt}\footnotesize\raggedright #1}%

    I then use this command in the table float as follows:

    \end{tabular}
    \end{center}
    \capbot{Data from the IMF's website: \url{http://www.imf.org/external/np/sec/memdir/members.htm.} Accessed 11 April 2007.}
    \label{nondemocfig}
    \end{table}

    This works quite nicely.

  11. Kai

    How to create a big table across a two-column latex document? I tried vertically put the big table in one column for the two-column latex document. But it looks ugly so I tried \minipage. However, it still does not help. Any suggestions?

  12. Hi Kai,

    What I suggest you to do is use the command \onecolumn, which will start a new page having only one column in your “two column environment” (see my previous post).
    Then you insert your table, depending on the height/width ratio you can even change the page layout to landscape.
    And finally, you switch back to a \twocolumn environment.

    Cheers,
    Tom

  13. Si

    Hi,

    Is it possible to have the two figures/tables aligned at the top stead at the bottom? I’ve tried \minipage[t] but it ended up with the top of the left figure/table aligned to the bottom of the right one. It looked as if the two figures/tables occupied the top right and bottom left of a 2×2 invisible grid.

    Thanks

  14. Hi Si,

    I had the same problem once I wanted to place a table next to a figure. Try to use subfigure instead of minipage, I’m not sure it will work, but it is worth a try.

    Note:
    Replace \begin{center}…\end{center} by \centering, which does not add any additional white space on top and below the figure/table.

  15. Hugo

    Hi.
    I’m trying to put a table and a picture side-by-side but my efforts are in vane.. who I can do that?

    I made this but its not working well…

    \begin{figure}[!h]
    \subfloat{
     \includegraphics[scale=0.5]{picture1}
    }
    \hspace{1.2cm}
    \subfloat{
    \begin{minipage}[t]{5cm}{5cm}
    \begin{tabular}{|c|c|c|}
    \hline
    \multicolumn{1}{|c|}{Sectores} & $[345;355[$ & $[355;5[$ \\
    \multicolumn{1}{|c|}{Factores de calibração} & 1.02 & 1.02\\
    \hline
    \end{tabular}
    \end{minipage}
    }
    \end{figure}
  16. Hi Hugo,

    There is indeed a problem in your code. Y only have one minipage for your tabular environment, but actually you need a minipage for the picture as well. So try this and let me know if you are still facing problems:

    \begin{figure}[!h]
    \begin{minipage}[b]{0.5\linewidth}
    \centering
    \includegraphics{picture1}
    \end{minipage}
    \hspace{1.2cm}
    \begin{minipage}[b]{0.5\linewidth}
    \centering
    \begin{tabular}{|c|c|c|}
    \hline
    \multicolumn{1}{|c|}{Sectores} & $[345;355[$ & $[355;5[$ \\
    \multicolumn{1}{|c|}{Factores de calibração} & 1.02 & 1.02\\
    \hline
    \end{tabular}
    \end{minipage}
    \end{figure}

    Cheers,
    Tom

  17. Amar Nath Satrawala

    Hi

    I am also trying to put a figure and a table side by side. They end up getting both Figure captions or table captions.

    I am not able to give simultaneously different captions i.e. figure to figure and table to table.

    Somebody please help.
    Cheers

    Amar

  18. Amar Nath Satrawala

    Hi

    I found the solution by modifying the help given in http://www.win.tue.nl/latex/documentation/plaatjes/pictures.pdf

    \parbox [h]{0.4\textwidth}{
    	\includegraphics [width=\linewidth]{drawing.eps}
    	\captionof {figure}{caption1}
    	\label{fig:draw}
    }
    %\hfill
    \hspace{0.5cm}
    \parbox [h]{0.4\textwidth }{
    	\captionof {table}{caption2}
    	\begin{tabular}{|c|l|}
    		\hline
                    a & b
    		\hline
    	\end{tabular}
    	\label{tab:table1}
    }
  19. Albert

    Laying out two tables of uneven length aligns both tables vertically in the middle. How would I align them both to the top?

    I think that this is exactly the problem that Si was asking about?

    • Hi Albert,

      I cannot reproduce what you are referring to. Can you please provide a minimal example? Might it be that your tables together are wider than the document’s “textwidth” and hence one is pushed to the next “line”?

      Cheers,
      Tom.

    • jpa

      Just for the record, aligning tables to top is possible by giving [t] to both minipage and the tabular:

      \begin{minipage}[t]{0.3\textwidth}
      \begin{tabular}[t]{ll}
      ...
  20. Michiel

    When i use the caption package, I got tons of errors after the place where I used the \captionof command… When I do not include the caption package, I only got 2 errors, there where I used the \captionof command…
    anyone?

    • Michiel

      My bad, found the problem. I had this error: “to many unprocessed floats”. By using the caption package, the size of some captions may be changed, and suddenly LaTeX placed all my figures at the end of the document. This happened with so many figures that LaTeX couldn’t put them down nicely on a page any more. By using the float package, I forced some figures in position, and problem solved.

      An other solution when you got the error is putting in a \clearpage or \cleardoublepage command to allow a page full of figures to be generated.

  21. Sunil

    Hey Amir,
    It was really helpful for me!! After a long search on google for ‘image beside a table’, I finally ended up using your code. :)

    Thanks again.

  22. M

    Hi!! I wanted to put two figures side by side, and the minipage stuff works fine. However, it doesn’t look good at all. The figures are not placed at the exact same height and I can’t place the captions exactly under each figure (probably cause of the page size, which i do not want to change) Also, I can’t put the figures at the center of the page, they either go too left or too right no matter what i do…

  23. M

    Great! This is the code:

    \begin{figure}[H]
    \begin{minipage}[b]{0.4\textwidth}
    \begin{flushleft} \large
    \hspace{-100pt} \includegraphics[angle=270 , scale=0.3]{misdip3.jpeg}
    \caption[Evolution of the beta functions and the dispersion through FODO 3]
    {\textit{Evolution of the beta functions and the dispersion through FODO 3.}}
    \end{flushleft}
    \end{minipage}
    \hspace{60pt}
    \begin{minipage}[b]{0.4\textwidth}
    \begin{flushright} \large
    \includegraphics[angle=270 , scale=0.3]{misdip4.jpeg}
    \hspace{100pt}\caption[Evolution of the phase advance through FODO 3]%
    {\textit{Evolution of the phase advance through FODO 3.}}
    \end{flushright}
    \end{minipage}
    \end{figure}
    • Hi,
      What I propose is using the “subfigure” package instead of “minipage”, which gives you more flexibility. You can find a general introduction here.

      If you want more space between the figure and the caption, use:

      \usepackage[loose]{subfigure}

      Also, if you prefer numbers instead of the default numbering:

      \renewcommand{\thesubfigure}{\thefigure.\arabic{subfigure}}

      Here is a link to the documentation: subfigure

      Another thing that might be useful is the caption package (i.e. page 9). Among other things, it lets you define the font style of the caption and hence you don’t need to type the caption twice:

      \usepackage[textfont=it]{caption}

      Hope this works! Let me know if you have any other question.

      Cheers, Tom.

      ps.: This should do:

      \begin{figure}[h]
      \subfigure[Evolution of the beta functions and the dispersion through FODO 3]{
      \includegraphics[angle=270 , scale=0.3]{misdip3.jpeg}
      }
      \qquad % double quadspace
      \subfigure[Evolution of the phase advance through FODO 3.]{
      \includegraphics[angle=270 , scale=0.3]{misdip4.jpeg}
      }
      \end{figure}
  24. fofo

    Hi,
    I’m trying to put a table and a figure side by side using the minipage environment but I have this problem:
    the caption of the figure is considered as a table :(
    how to solve this ???
    regards

  25. christina

    hi Tom!
    i have to try make 2 lanscape table in 1 page. But the table can’t center,
    The top and bottom margin not same. How to solve this problem?could u?

    Cheers=)

    • Hi Christina,

      Do you want to rotate a single page and have two tables on that page in landscape format? If so, here is how you can achieve that:

      \usepackage{pdflscape}
      ...
      \begin{landscape}
      % Table 1
      %Table2
      \end{landscape}

      If this is not what you wanted, please provide code of a mini-example. Cheers, Tom.

  26. Jorge

    Amir, your code worked wonderfully for me. I had been struggling with the format till I tried your solution.

    It turns out the issue was the [b] option after each \minipage command that made it look bad, ie, the table and the figure were placed side by side, but the figure was below the table. I removed that option and voilà, it worked.

    Thank you all!

  27. sschmid

    Easiest solution (columns):

    \begin{columns}
    \begin{column}{0.5\textwidth}
    %text,figure..
    \end{column
    
    \begin{column}{0.5\textwidth}
    %...
    \end{column
    \end{columns}

    the rest all didn’t work for me (minipages, wrapfigure, parbox..), it kept aligning the elements top-down, if at all.

  28. sarvesh

    Dear Bob , I have 40 subfigure which i want to display with caption F1,F2, …F40 under single banner. I do not want to display figure numbering like (a) F1 (b) F2 (c) F3… etc instead of it i want to display F1 F2 F3 F4…etc
    please help me.
    Thanks

    regards
    sarvesh

    • Hi Sarvesh,

      Below is a minimal working example where subfloats have no label. For more information see my post, the subfig and caption package documentations. Best, Tom.

      \documentclass[11pt]{article}
      \usepackage{subfig, caption}
      \captionsetup[subfigure]{labelformat=empty}
      \begin{document}
      \begin{figure}[h]
      	\centering
      	\subfloat[][F1]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F2]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F3]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F4]{\rule{2.5cm}{2cm}}\\
      	\subfloat[][F5]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F6]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F7]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F8]{\rule{2.5cm}{2cm}}\\
      	\subfloat[][F9]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F10]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F11]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F12]{\rule{2.5cm}{2cm}}\\
      	\subfloat[][F13]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F14]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F15]{\rule{2.5cm}{2cm}}\quad
      	\subfloat[][F16]{\rule{2.5cm}{2cm}}
      \end{figure}
      \end{document}
    • Hi Steven,

      In general, they are stacked vertically if there is not enough space to arrange them horizontally. For figures, try using the width option, e.g.:

      \usepackage{graphicx}
      ...
      \includegraphics[width=0.4\textwidth]{figure.file}

      If you provide a minimal working example, I may be able to help you better.

      Best, Tom.

  29. Kevin

    Hi Tom,

    I’m having a similar problem to Steven above. I’m using the code you provided to place mini pages horizontally, but they only stack vertically. Because of the cautionary note about the size of figures, I’ve attempted to remedy this by decreasing the image size and the buffer space between the images. Even though the figures are now only an inch across they still stack vertically. The code is as follows:

    \begin{figure}[ht]
    \begin{minipage}[b]{0.5\linewidth}
    \centering
    \includegraphics[width=1.0in]{Figure1}
    \caption{default}
    \label{fig:figure1}
    \end{minipage}
    \hspace{0.1cm}
    \begin{minipage}[b]{0.5\linewidth}
    \centering
    \includegraphics[width=1.0in]{Figure2}
    \caption{default}
    \label{fig:figure2}
    \end{minipage}
    \end{figure}

    Any suggestions?

    Thanks!

    • Hi Kevin,

      The problem is not so much with the size of the figures inside the minipage environment, but the size of the minipage “box” itselves. Including the small horizontal space in-between, they are taking up more than the complete linewidth. Try reducing their sizes slightly and it should work just fine.

      Example:

      \begin{figure}[ht]
      \begin{minipage}[b]{0.48\linewidth} % page linewidth
      \rule{\linewidth}{\linewidth} % minipage linewidth
      \end{minipage}
      \qquad
      \begin{minipage}[b]{0.48\linewidth}
      \rule{\textwidth}{\textwidth}\end{minipage}
      \end{figure}

      Cheers, Tom.

  30. Tess

    \begin{figure}[ht]
    \begin{minipage}[b]{0.45\linewidth}
    \centering
    \begin{tikzpicture}
    \draw [] (-3,0) -- (3,0) node [above left]  {$v_{\theta}$};
    \draw [] (0,-3) -- (0,3) node [below right] {$v_r$};
    \draw[
            decoration={markings, mark=at position 0.525 with {\arrow[scale=2]{<}}},
            decoration={markings, mark=at position 0.925 with {\arrow[scale=2]{<}}},
            postaction={decorate}
            ]
            (0,0) circle (1.5);
            \fill[very thick] (-1.5,0) circle (1pt) node [above left] {A};
            \fill[very thick] (0,1.5) circle (1pt) node [above right] {B};
            \fill[very thick] (1.5,0) circle (1pt) node [above right] {C};
            \fill[very thick] (0,-1.5) circle (1pt) node [below right] {D};
    \end{tikzpicture}
    \captionof{figure}{Engagement trajectory 1 in $(v_{r},v_{\theta})$ space}
    \label{fig:aba}
    %\end{center}
    \end{minipage}
    \hspace{0.5cm}
    
    \begin{minipage}[b]{0.45\linewidth}
    \centering
    \begin{tikzpicture}
    \draw [] (-3,0) -- (3,0) node [above left]  {$v_{\theta}$};
    \draw [] (0,-3) -- (0,3) node [below right] {$v_r$};
    \draw[
            decoration={markings, mark=at position 0.925 with {\arrow[scale=2]{>}}},
            decoration={markings, mark=at position 0.125 with {\arrow[scale=2]{<}}},
            postaction={decorate}
            ]
            (0,-1) arc (-45:45:2);
    \fill[very thick] (0,1.77) circle (1pt) node [above right] {B};
    \fill[very thick] (1,0) circle (1pt) node [above right] {A};
    \fill[very thick] (0,-1) circle (1pt) node [below right] {C};
    \end{tikzpicture}
    \captionof{figure}{Engagement trajectory 2 in $(v_{r},v_{\theta})$ space}
    \label{fig:bab}
    %\end{center}
    \end{minipage}
    \end{figure}

    ### Why am I not getting the images side-by-side?

    • Hi Tess,

      Nice figures :-)! The space (line 23) ends the paragraph in LaTeX which is why the second figure is on the “next line” or below the first. Simply delete it and it should work. Also, \hspace is fine, however, LaTeX has standard space commands: \quad and \qquad. I recommend to use these. Finally, please provide a minimal working example including preamble next time, so I don’t have to figure out which packages and TikZ libraries you use.

      Thanks, Tom.

      \documentclass{article}
      \usepackage{tikz, caption}
      \usetikzlibrary{decorations.markings}
      \begin{document}
      ...
      \end{minipage}
      \qquad
      \begin{minipage}[b]{0.45\linewidth}
      ...
      \end{document}
  31. Tess

    Hi I want to align two conditional statements like we do using the \begin{split} command. In the following code, I want to align z3 and z4.

    \documentclass[a4paper,12pt]{report}
    \usepackage{tikz}
    \usetikzlibrary{decorations.markings,arrows}
    \usepackage {graphicx}
    \usepackage{textcomp}
    \usepackage{float}
    \usepackage{amsmath}
    \usepackage{amsmath,amscd,amssymb,amsgen,amsfonts,amsbsy}
    \usepackage{mathrsfs}
    %\usepackage[utf8x]{inputenc}
    \usepackage{color}
    \usepackage{textcomp}
    \usepackage{float}
    \usepackage{latexsym,graphicx}
    \usepackage[british]{babel}
    \usepackage{caption}
    
    \usepackage{pgf}
    \usepackage{indentfirst}
    \usepackage[left=20mm,top=20mm,right=20mm,bottom=22mm,foot=13mm]{geometry}
    
    \begin{document}
    
    \begin{equation}
    z_3 = \begin{cases}
    z_{2} & \text{if $-K_{br} < K < 0$}\\
    -\left( \frac{K}{2} + \sqrt{\frac{K^2}{4} + \frac{v^3}{k^3}} \right)^\frac{1}{3} & \text{if $~0 < K < \infty$}\\
    \end{cases}
    \\
    z_4 =
    \begin{cases}
        z_{1},& \text{if } -K_{br} < K < 0\\
       -\left( \frac{K}{2} - \sqrt{\frac{K^2}{4} + \frac{v^3}{k^3}} \right)^\frac{1}{3},   & \text{if}~ 0 < K < \infty
    \end{cases}\\
    \end{equation}
    
    \end{document}
    • Hi Tess,

      I assume by align, you mean vertically align z_3 and z_4. Btw. you are loading several packages multiple times, including textcomp, float and amsmath. Not that it was wrong, but remember that sometimes the order makes a difference.

      Cheers, Tom.

      \documentclass{article}
      \usepackage{amsmath}
      \begin{document}
      \begin{align*}
      z_3 &= \begin{cases}
      z_{2} & \text{if $-K_{br} < K < 0$}\\
      -\left( \frac{K}{2} + \sqrt{\frac{K^2}{4} + \frac{v^3}{k^3}} \right)^\frac{1}{3} & \text{if $~0 < K < \infty$}\\
      \end{cases}
      \\z_4 &=
      \begin{cases}
          z_{1},& \text{if } -K_{br} < K < 0\\
         -\left( \frac{K}{2} - \sqrt{\frac{K^2}{4} + \frac{v^3}{k^3}} \right)^\frac{1}{3},   & \text{if}~ 0 < K < \infty
      \end{cases}
      \end{align*}
      \end{document}
  32. Tess

    Thanks again Tom ! They are definitely getting aligned ! But I wanted them left aligned..that way they look better ! So, I used \begin{flalign*},
    but that doesnot work ! Is there any other way to left align the conditional
    equations?

    • In case you mean left in the document, you can pass the fleqn option to either documentclass or the amsmath package.

      \documentclass[fleqn]{report}

      or

      \usepackage[fleqn]{amsmath}

      To align the equations, this should work:

      \documentclass{article}
      \usepackage{amsmath}
      \begin{document}
      \begin{flalign*}
       z_1 &= -\left( \frac{K}{2} + \sqrt{\frac{K^2}{4} - \frac{v^3}{k^3}} \right)^\frac{1}{3}\\
       z_2 &= -\left( \frac{K}{2} - \sqrt{\frac{K^2}{4} - \frac{v^3}{k^3}} \right)^\frac{1}{3}\\
       z_3 &= \begin{cases}
      z_{2} & \text{if $-K_{br} < K < 0$}\\
      -\left( \frac{K}{2} + \sqrt{\frac{K^2}{4} + \frac{v^3}{k^3}} \right)^\frac{1}{3} & \text{if $~0 < K < \infty$}\\
      \end{cases}\\
       z_4 &=
      \begin{cases}
          z_{1} & \text{if } -K_{br} < K < 0\\
         -\left( \frac{K}{2} - \sqrt{\frac{K^2}{4} + \frac{v^3}{k^3}} \right)^\frac{1}{3}   & \text{if}~ 0 < K < \infty
      \end{cases}\\
       a &= \begin{cases}
          \frac{1+i\sqrt{3}}{2},& \text{if } -K_{br} < K < 0\\
          1,              & \text{if} ~0 < K < \infty
      \end{cases}\\
       b &= \begin{cases}
          \frac{1-i\sqrt{3}}{2},& \text{if } -K_{br} < K < 0\\
          1,              & \text{if} ~0 < K < \infty
      \end{cases}\\
      \end{flalign*}
      \end{document}
  33. Tess

    Hi all !

    \documentclass[10pt]{beamer}
    \mode {
    \usecolortheme[named=yellow]{structure}
      %\usetheme{Warsaw}
      \usetheme{Ilmenau}
    %\usetheme{Copenhagen}
    % \usetheme{CambridgeUS}
      %\usethemes{Amsterdam}
      \setbeamercovered{invisible}
    }\usepackage[english]{babel}
    \usepackage[latin1]{inputenc}
    \usepackage{times}
    %\usepackage{iwona}
    \usepackage[T1]{fontenc}
    \usepackage{amsmath,amssymb}
    \usepackage{colortbl}
    \usepackage{array}
    \usepackage{longtable}
    \usepackage{rotating}
    \usepackage{fancyvrb}
    \usepackage{psfrag}
    \usepackage{graphicx}
    \usepackage{color}
    %\usetikzlibrary{decorations.markings,arrows}
    \definecolor{red}{rgb}{1,0.2,0.2}
    \definecolor{blue}{rgb}{0,0,1}
    \definecolor{green}{rgb}{0,0.7,0}
    \definecolor{black}{rgb}{0.2,0.2,0.2}
    \definecolor{orange}{rgb}{1,0.7,0}
    \definecolor{brown}{rgb}{0.8,0.2,0.2}
    \usepackage{tikz}
    %\PreviewEnvironment{tikzpicture}
    \usetikzlibrary{matrix}
    \newcommand{\red}[1]{\textcolor{red}{#1}}
    \newcommand{\blue}[1]{\textcolor{blue}{#1}}
    \newcommand{\green}[1]{\textcolor{green}{#1}}
    \newcommand{\black}[1]{\textcolor{black}{#1}}
    \newcommand{\orange}[1]{\textcolor{orange}{#1}}
    \newcommand{\brown}[1]{\textcolor{brown}{#1}}
    \newcommand{\bi}{\begin{itemize}}
    \newcommand{\ei}{\end{itemize}}
    \newtheorem{thm}{Theorem}[section]
    \newtheorem{lm}[thm]{\bf Lemma}
    \newtheorem{prob}[thm]{\bf Problem Statement}
    \newtheorem{df}[thm]{\bf Definition}
    \newtheorem{pr}[thm]{\bf Proposition}
    \newtheorem{rem}[thm]{\bf Remark}
    \newtheorem{algo}[thm]{\bf Algorithm}
    \newtheorem{corr}[thm]{\bf Corollary}
    \newtheorem{eg}[thm]{\bf Example}
    \DeclareMathAlphabet{\mathpzc}{OT1}{pzc}{m}{it}
    %\pagestyle{plain}
    \title[Coverage Control Algorithm]{Coverage Control Algorithm}
    \author[IIT Bombay]{Twinkle Tripathy}
    \institute[Systems and Control Engineering] {Systems and Control Engineering \\
    IIT Bombay }
    \date{Oct 30, 2012}
    \begin{document}
    \begin{frame}
    \titlepage
    \end{frame}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{frame}
    \frametitle{Introduction}
    \begin{block}{Motivation}
    \begin{itemize}
    \item Missile Guidance Strategies
    \item Coverage of a pre-defined area
    %\item
    \end{itemize}
    \end{block}
    \begin{block}{Application}
    \begin{itemize}
    \item Surveillance of landmarks
    \item Spraying fertilisers, irrigation of fields
    \end{itemize}
    \end{block}
    \end{frame}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{frame}
    \frametitle{}
    \begin{block}{Problem Statement}
    \begin{itemize}
    \item Propose a strategy for autonomous robot to cover the area surrounding the steady target using range(distance) information only.
    \item The area to be covered is pre-defined by maximum and minimum radii, $R_{max}$ and $R_{min}$.
    \end{itemize}
    \end{block}
    \begin{block}{Kinematics of robot}
    \begin{eqnarray}
    {\dot x} = vcos(\alpha)\\
    {\dot y} = vsin(\alpha)\\
    {\dot {\alpha}} = u
    \end{eqnarray}
    \end{block}
    \end{frame}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{frame}{Mathematical Analysis}
    \begin{center}
    \begin{tikzpicture}[scale=2]
     \draw [->] (0,0) -- (2.5,2.5) ;
     \draw [dashed, ->] (0,0) -- (4.5,0) node [below]  {Reference};
     \draw [->](0,0) -- (0.3,1.5);
     \node [right] at (0.3,1.5) {$v$};
     \node [below] at (0,0) {A};
     \draw [->](1,0) arc (0:45:1);
     \node [right] at (1,0.5) {$\theta$};
     \draw [->](0.5,0) arc (0:60:0.8);
     \node [right] at (0.55,0.25) {$\alpha$};
     \fill[very thick] (2.5,2.5) circle (1pt) node [above right] {T};
     \fill[very thick] (1.5,1.5) circle (1pt) node [right] {VT};
     \node [right] at (1,1) {$ (1-\rho)r $};
     \node [right] at (2,2) {$\rho r$};
     %\node [left] at (2.25,2.25) {$d$};
     %\fill[very thick] (1,1) circle (1pt) node [right] {$\rho$};
     %\fill[very thick] (2.25,2.25) circle (1pt) node [right] {$(1-\rho)$};
    \end{tikzpicture}
    \captionof{figure}{Engagement geometry between the agent and the target point}
    \label{fig:aaa}
    \end{center}
    \end{frame}
    \end{document}

    Why are my tikz figures not getting generated?

    • Hi!
      Please only sent the code that is absolutely necessary to reproduce the issue. Including the LaTeX error would also be useful.

      Could it be that your editor replaces double dash by a long dash? I had to replace the dashes on the lines highlighted below. Other than that, your tikz figure seems to be ok.

      Cheers, Tom.

      \documentclass{beamer}
      \usepackage[english]{babel}
      \usepackage[latin1]{inputenc}
      \usepackage[T1]{fontenc}
      \usepackage{tikz, caption}
      \begin{document}
      \begin{frame}{Mathematical Analysis}
      \begin{center}
      \begin{tikzpicture}[scale=2]
      \draw [->] (0,0) -- (2.5,2.5) ;
      \draw [dashed, ->] (0,0) -- (4.5,0) node [below] {Reference};
      \draw [->](0,0) -- (0.3,1.5);
      \node [right] at (0.3,1.5) {$v$};
      \node [below] at (0,0) {A};
      \draw [->](1,0) arc (0:45:1);
      \node [right] at (1,0.5) {$\theta$};
      \draw [->](0.5,0) arc (0:60:0.8);
      \node [right] at (0.55,0.25) {$\alpha$};
      \fill[very thick] (2.5,2.5) circle (1pt) node [above right] {T};
      \fill[very thick] (1.5,1.5) circle (1pt) node [right] {VT};
      \node [right] at (1,1) {$ (1-\rho)r $};
      \node [right] at (2,2) {$\rho r$};
      \end{tikzpicture}
      \captionof{figure}{Engagement geometry between the agent and the target point}
      \label{fig:aaa}
      \end{center}
      \end{frame}
      \end{document}
    • Hi Michael,

      Thanks for your comment. I’m not sure what you are doing exactly. But if you need captions for your figures, you might be better off using either subfigure or the more recent subfig package.

      Nevertheless, here is a minimal example with two figures, each with a caption.

      \documentclass[11pt]{article}
      \begin{document}
      \begin{figure}[ht]
      \begin{minipage}[b]{0.45\linewidth}
      \centering
      \rule{\textwidth}{0.75\textwidth}
      \caption{default}\label{fig:figure1}
      \end{minipage}
      \hspace{0.5cm}
      \begin{minipage}[b]{0.45\linewidth}
      \centering
      \rule{\textwidth}{0.75\textwidth}
      \caption{default}\label{fig:figure2}
      \end{minipage}
      \end{figure}
      \end{document}

      Best, Tom.

  34. Barry

    Hi, I am struggling with a captioning issue in minipage. The error I get states “Package floatrow Error: Caption(s) lost.” I have tried reading around this but cant find a solution to the issue. The code is one i have used previously and successfully so have no idea why it is now not working. Can anyone offer advice please?

    General code used is as follows:

    \begin{figure}[htbp]
    	\begin{minipage}[b]{0.5\linewidth}
    	\centering
    		\includegraphics[width=0.95\textwidth]{photo1.jpg}
    	\caption[photo1]{photo1}
    	\label{fig:photo1}
    	\end{minipage}
    \hspace{0.5cm}
    	\begin{minipage}[b]{0.5\linewidth}
    	\centering
    		\includegraphics[width=0.95\textwidth]{photo2.jpg}
    	\caption[photo2}]{photo2}
    	\label{fig:photo2}
    	\end{minipage}
    \end{figure}

    Many thanks in advance for any assistance given, greatly appreciated.

    • Hi Barry,

      Your code works perfectly, the only problem was a “}” in the short caption of the second figure. The conflict is due to the floatrow package (as the error suggests). Remove it in case you don’t need it. Otherwise, I would need to see a minimal example which produces the error to be able to help.

      Here is a complete minimal working example just using minipage including captions:

      \documentclass[11pt]{article}
      \begin{document}
      \listoffigures
      \begin{figure}[ht]
      	\begin{minipage}[b]{0.5\linewidth}
      	\centering
      		\rule{\textwidth}{0.75\textwidth}
      	\caption[photo1]{photo1}
      	\label{fig:photo1}
      	\end{minipage}
      \hspace{0.5cm}
      	\begin{minipage}[b]{0.5\linewidth}
      	\centering
      		\rule{\textwidth}{0.75\textwidth}
      	\caption[photo2]{photo2}
      	\label{fig:photo2}
      	\end{minipage}
      \end{figure}
      \end{document}
  35. Barry

    HI Tom,

    Thank you very much for the prompt reply. I tried the altered code and still get the same error :(.

    I have included the code proper below, I am just at a loss as to why it used to work fine and now doesnt. Beginning to wonder if I have a package conflict.

    \documentclass[11pt]{article}
    \begin{document}
    \listoffigures
    \begin{figure}[ht]
    	\begin{minipage}[b]{0.5\linewidth}
    	\centering
    	\includegraphics[width=0.90\textwidth]{apatite.jpg}
    		\rule{\textwidth}{0.75\textwidth}
    	\caption[Photograph of apatite mineral]{Photograph of apatite mineral. Credit: Photograph from The Delaware Mineral Society.}
    	\label{fig:apatite}
    	\end{minipage}
    \hspace{0.5cm}
    	\begin{minipage}[b]{0.5\linewidth}
    	\centering
    	\includegraphics[width=0.90\textwidth]{Whitlockite.jpg}
    		\rule{\textwidth}{0.75\textwidth}
    	\caption[Photograph of whitlockite mineral]{Photograph of whitlockite mineral. Credit: Photograph from Royal Ontario Museum.}
    	\label{fig:whitlockite}
    	\end{minipage}
    \end{figure}
    \end{document}

    Thanks for the assistance once again

    • Again, the code works perfectly (apart from the missing graphicx package). You would need to give me an example that includes the packages you load, so I can reproduce the error. I.e., are you loading floatrow? Another possibility would be to use either subfigure or subfig. You might want to give those packages a try to see if it solves your problem.

      Best, Tom.

  36. muninder

    Hi Tom,
    Iam using this code to display images side by side. However I want to reduce the space between the displayed images even further(ideally < 2mm seperating every image) , so that I can increase the size of every image and still display in one row. At present the seperation is around ~1cm between two images with the below code. can you suggest how to do this using minipage ?

    \begin{figure}[h]
    \centering
    \begin{minipage}{.11\textwidth}
    \includegraphics[width=\textwidth]{Fig/I1}
    \end{minipage}
    \begin{minipage}{.11\textwidth}
    \includegraphics[width=\textwidth]{Fig/I2}
    \end{minipage}
    \begin{minipage}{.11\textwidth}
    \includegraphics[width=\textwidth]{Fig/I3}
    \end{minipage}
    \begin{minipage}{.11\textwidth}
    \includegraphics[width=\textwidth]{Fig/I4}
    \end{minipage}
    \begin{minipage}[b]{0.38\linewidth}
    \caption{\small Original frames.\label{fig:caption}}
    \end{minipage}
    • I suggest using \hfill, which basically fills whatever space is available. Here is your example with \hfill:

      \documentclass[11pt]{article}
      \begin{document}
      \begin{figure}[h]
      \centering
      \begin{minipage}{.11\textwidth}
      \rule{\textwidth}{0.75\textwidth}\end{minipage}\hfill
      \begin{minipage}{.11\textwidth}
      \rule{\textwidth}{0.75\textwidth}\end{minipage}\hfill
      \begin{minipage}{.11\textwidth}
      \rule{\textwidth}{0.75\textwidth}\end{minipage}\hfill
      \begin{minipage}{.11\textwidth}
      \rule{\textwidth}{0.75\textwidth}\end{minipage}\hfill
      \begin{minipage}[b]{0.38\linewidth}
      \rule{\textwidth}{0.75\textwidth}\end{minipage}
      \end{figure}
      \end{document}

      Best, Tom.

  37. Roman

    Hi Tom, first of all you have a great and very helpful blog. All of this information helped me place 2 figures side by side and a table and a firgure side by side (using the minipage command). I have 2 questions: One- Is it possible to place two figures side by side and immediately below them another two figures, all of these as one “unit”?
    Two- It’s a bit hard to explain (I’d send you a pic but don’t know how), but as I’m making a table I’d like to know how to control the lines, e.g. I have three columns and above them one cell which is not divided by the lines of thecolumns below… Do you have any suggestions?

    Thanks,

    Roman

    • Hi Roman,

      Thanks for your question. I’ll try to answer both below.

      Question 1
      Consider using the subfig package which I wrote about in this post. It’s more suitable for complex figures and supports captioning and referencing. Here is an example:

      \documentclass[11pt]{article}
      \usepackage[lofdepth]{subfig}
      \begin{document}
      \listoffigures
      \begin{figure}[h]
      \centering
       \subfloat[first lof][first caption]{
         \rule{0.45\linewidth}{0.35\linewidth}
       }
       \quad
       \subfloat[second lof][second caption]{
         \rule{0.45\linewidth}{0.35\linewidth}
       }
      
      \subfloat[third lof][third caption]{
         \rule{0.45\linewidth}{0.35\linewidth}
      }
      \quad
      \subfloat[forth lof][forth caption]{
         \rule{0.45\linewidth}{0.35\linewidth}
      }
      \caption{General figure caption}
      \end{figure}
      \end{document}

      Question 2
      The tabular environment knows multicolumn cells. This article explains how to do it with a basic example.

      Hope it helps!
      Tom

      • Roman

        Hey Tom, I’ve tried out your solution but then LaTeX informs me that this \usepackage[lofdepth]{subfig} package can’t work with \usepackage{subcaption}. I’m sorry I didn’t post what I’m using before:

        \documentclass[12pt,a4paper]{report}
        \usepackage{amsmath}
        \usepackage[utf8]{inputenc}
        \usepackage{amssymb}
        \usepackage[croatian]{babel}
        \usepackage[pdftex]{graphicx}
        \usepackage{graphicx}
        \usepackage{caption}
        \usepackage{subcaption}
        \usepackage{units}
        %\usepackage[margin=2.5cm]{geometry}
        %\usepackage[top=3.5cm, bottom=3.8cm, left=3.5cm, right=3.3cm]{geometry}
        \usepackage[top=2.7cm, bottom=3.0cm, left=2.7cm, right=2.5cm]{geometry}
        \usepackage{indentfirst}
        \usepackage{color}
        \usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
        \linespread{1.5}
        \usepackage[margin=10pt,font=small,labelfont=bf]{caption}
        \usepackage{booktabs}
        \title{}
        \date{}
        
        \newenvironment{packed_enum}{
        \begin{enumerate}
          \setlength{\itemsep}{1pt}
          \setlength{\parskip}{0pt}
          \setlength{\parsep}{0pt}
        }{\end{enumerate}}
        
        \usepackage[pdftex]{hyperref}
        \hypersetup{
            colorlinks,%
            citecolor=black,%
            filecolor=black,%
            linkcolor=black,%
            urlcolor=black
        }
      • Hi Roman,

        The more recent subcaption package provides similar functionality to subfig. See the package documentation for more details. Here is the same example using subcaption:

        \documentclass[11pt]{article}
        \usepackage{caption}
        \usepackage[list=true]{subcaption}
        \begin{document}
        \listoffigures
        \section{Test section}
        \begin{figure}[ht]
        \begin{subfigure}[b]{.49\linewidth}
        	\centering
        	\rule{\linewidth}{0.65\linewidth}
        	\caption{Subfigure 1}\label{fig:1a}
        \end{subfigure}%
        \quad
        \begin{subfigure}[b]{.49\linewidth}
        	\centering
        	\rule{\linewidth}{0.65\linewidth}
        	\caption{Subfigure 2}\label{fig:1b}
        \end{subfigure}%
        
        \begin{subfigure}[b]{.49\linewidth}
        	\centering
        	\rule{\linewidth}{0.65\linewidth}
        	\caption{Subfigure 3}\label{fig:1c}
        \end{subfigure}%
        \quad
        \begin{subfigure}[b]{.49\linewidth}
        	\centering
        	\rule{\linewidth}{0.65\linewidth}
        	\caption{Subfigure 4}\label{fig:1d}
        \end{subfigure}%
        \caption{A figure}\label{fig:1}
        \end{figure}
        \end{document}
  38. Roman

    Ok thanks and where do I put my pictures in the code? like I had to do before e.g. \includegraphics[width=\textwidth]{3sim1x1d1_30.jpg} :)

    • Hi Roman,

      In my example, the \rule command is just a placeholder for the figure. So, all you have to do is replace them with your figures (\includegraphics).

      Tom

  39. Adam

    Dear All,

    I have a problem that I cannot handle based on the forums I have read: using minipage, the [H] command does not work, the image disappears when I compile the source. Here is my code:

    \begin{figure*}
    \begin{minipage}{0.43\textwidth}
    \includegraphics[width=\columnwidth]{./figures/blk3.eps}
    \end{minipage}
    \begin{minipage}{0.43\textwidth}
    \includegraphics[width=\columnwidth]{./figures/resch.eps}
    \end{minipage}
    \caption{Scenario 1 -- the ratio and the average number of occupied channels\label{fig:scenario1a}}
    \end{figure*}

    What should I do?

    Thanks in advance.
    Adam

    • Hi Adam,

      Thanks for the code. Do you use [H] on minipage? Try [H] or [h!t] on the figure.

      Please provide a complete minimal working example next time, including preamble.

      Best, Tom.

  40. Adam

    Hi Tom,

    thanks for the quick answer. I tried [H] and now [h!t] on the figure! Using [H], the figure disappears, using [h!t], the figure appears, but not on the defined area.

    Adam

    • Hi Adam,

      Glad it works! Hard to say why [H] doesn’t though. As I said, I’d need to see the code…

      Cheers,
      Tom

  41. Adam

    Hi Tom,

    I try to do my best :) However, I don’t know exactly what you need to help me.

    \documentclass[10pt]{IEEEtran}
    
    \usepackage{amsmath}
    \usepackage{amsfonts}
    \usepackage{epsfig}
    \usepackage{amssymb}
    \usepackage{psfrag}
    \usepackage{graphicx}
    \usepackage{float}
    
    \newcommand{\hide}[1]{}
    \newcommand{\TBD}[1]{\footnote{{TBD: #1}}}
    
    \newtheorem{theorem}{\bf Theorem}[section]
    \newtheorem{clause}{\bf Clause}[section]
    \newtheorem{lemma}{\bf Lemma}[section]
    \newtheorem{corollary}{\bf Corollary}[section]
    \newtheorem{definition}{\bf Definition}[section]
    \newtheorem{remark}{\bf Remark}[section]
    \newtheorem{algorithm}{\bf Algorithm}[section]
    %...
    \begin{document}
    \maketitle
    
    \begin{abstract}
    \input{abstract}
    \end{abstract}
    
    \begin{keywords}
    opportunistic spectrum access, mobile cellular networks, spectrum sharing policy;
    \end{keywords}
    
    \thispagestyle{empty}
    
    \section{Introduction}\label{intro}
    \input{intro}
    \section{The Proposed Spectrum Sharing Policy}\label{background}
    \input{background}
    \section{System Model}\label{sysmodel}
    \input{sysmodel}
    \section{Simulation Results}\label{simresults}
    \input{simresults}
    \section{Conclusions\label{conc}}
    \input{conclusions}
    
    
    \bibliographystyle{ieeetr}
    \bibliography{paper}
    \end{document}
    
    %Comment to Tom:
    %Now I paste the section that contains the figures
    
    %...
    \subsection{Scenario 1}
    %bla-bla-bla
    \begin{figure*}[H]
    \begin{minipage}{0.43\textwidth}
    \includegraphics[width=\columnwidth]{./figures/blk3.eps}
    \end{minipage}
    \begin{minipage}{0.43\textwidth}
    \includegraphics[width=\columnwidth]{./figures/resch.eps}
    \end{minipage}
    \caption{Scenario 1 -- the ratio and the average number of occupied channels\label{fig:scenario1a}}
    \end{figure*}

    I hope it is enough. Thank you for helping me.
    Adam

    • Hi Adam,

      Ideally, the code would illustrate your problem with as few lines as possible.

      The problem is not related to eps-figures. You have two options:

      1. Use your code without [H] and move the figure forward until you get it where you want. The figure will always end up at the top of the page.
      2. If you need the figure to display in the middle of a page, you can use multicol. The figure, however, will break the page. In other words, the first column is filled to the figure before switching to column two and not to the bottom of the page. I added an example below
      \documentclass[a4paper, onecolumn]{article}
      \usepackage{multicol}
      \usepackage{blindtext}
      \usepackage{float}
      \begin{document}
      \begin{multicols}{2}
      \blindtext
      \end{multicols}
      \begin{figure}[H]
      \centering
      \rule{\textwidth}{0.3\textwidth}
      \caption{Single column figure}
      \end{figure}
      \begin{multicols}{2}
      \blindtext
      \end{multicols}
      \end{document}

      Best, Tom

      • Adam

        Hello Tom,

        thank you for the fine explanation and the code.

        Best wishes,
        Adam

Leave a Reply