Git Product home page Git Product logo

easysubfig's Introduction

Easysubfig

Easysubfig is a useful LaTeX snippet for creating subfigures. Sometimes you have a series of figures with different heights, and you want to align them at the bottom or top. When you use the minipage environment, the images are aligned based on the baseline of the first line of the minipage or the last line of the minipage (t or b option). What we want is to align the subfigures based on the baseline of the first line of the caption, and to be able to add spacing below the image to adjust the height. Easysubfig allows you to do this.

Easysubfig allows you to add custom spacing between the image and the caption. For example figure 3 adds a spacing of 10pt between the image and the caption.

\begin{figure}[h]
    \easysubfig[caption={demo \label{fig:1}}, width={0.33\textwidth}]{figs/demo.pdf}%
    \easysubfig[caption={demo \label{fig:2}}, width={0.33\textwidth}]{figs/demo.pdf}%
    \easysubfig[caption={demo \label{fig:3}}, width={0.33\textwidth}, spacing=10pt]{figs/demo2.pdf}%
\end{figure}

example

Arranging multiple subfigures side by side is very common in many conference papers. Feel free to use this code to save yourself from the hassle of constantly adjusting subfigures.

Usage

Add the following code to your LaTeX preamble:

\usepackage{graphicx}
\usepackage{caption}

\makeatletter
\define@key{easysubfig}{width}{\def\csf@width{#1}}
\define@key{easysubfig}{spacing}{\def\csf@spacing{#1}}
\define@key{easysubfig}{caption}{\def\csf@caption{#1}}

\NewDocumentCommand{\easysubfig}{O{} m}{%
  \begingroup%
  \setkeys{easysubfig}{width=\textwidth,spacing=0pt,#1}%
  \begin{minipage}[t]{\csf@width}
    \begin{minipage}[b]{\textwidth}
        \centering
        \includegraphics{#2} \\
        \vspace{\csf@spacing}
    \end{minipage}%
    \captionsetup{width=.9\linewidth, skip=0pt}
    \caption{\csf@caption}
  \end{minipage}%
  \endgroup%
}
\makeatother

easysubfig's People

Contributors

clysto avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.