Positioning images and tables

LATEX is an editing tool that takes care of the format so you only have to worry about the contents of your document. Nevertheless, sometimes a better control of floating elements is necessary. This article explains how to position images and tables in a LATEX document.

Contents

Introduction

The default alignment for images and tables is set to left

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra
sollicitudin.
 
\includegraphics[width=0.5\textwidth]{lion-logo}
 
Praesent imperdiet mi nec
ante. Donec ullamcorper, felis non sodales commodo, lectus velit
ultrices augue, a dignissim nibh lectus placerat pede.
Vivamus nunc nunc, molestie ut, ultricies
vel, semper in, velit. Ut porttitor.

This is a simple example, for a description of this and other ways to include images in your LATEX file see the article Inserting Images.

Open an example in ShareLaTeX

Positioning images

Basic positioning

To change the default alignment of a image from left or right an easy manner is to add

\usepackage[export]{adjustbox}

to the preamble of your file and then use an additional option in your image importing statement

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisis sem. Nullam nec mi et neque
pharetra sollicitudin.
 
\includegraphics[width=0.5\textwidth, right]{lion-logo}
 
Praesent imperdiet mi necante. Donec ullamcorper, felis
non sodales commodo, lectus velit ultrices augue,
a dignissim nibh lectus placerat pede. Vivamus nunc nunc,
molestie ut, ultriciesvel, semper in, velit. Ut porttitor.

The package adjustbox enables an additional option in the \includegraphics command, in the example the picture is aligned to right. The available values are: leftrightcenterouter and inner, the last two are intended for two-sided documents.

Open an example in ShareLaTeX

The figure environment

The figure environment (see Inserting Images) is intended to provide automatic positioning.

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Duis fringilla tristique neque. Sed interdum libero ut metus.
Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit amet
ante lobortis sollicitudin.
 
\begin{figure}[h]
\includegraphics[width=0.5\textwidth, inner]{lion-logo}
\caption{Caption}
\label{fig:figure2}
\end{figure}

This environment uses a positioning parameter passed inside brackets, it can take the next values:

Parameter Position
h Place the float here, i.e., approximately at the same point it occurs in the source text (however, not exactly at the spot)
t Position at the top of the page.
b Position at the bottom of the page.
p Put on a special page for floats only.
! Override internal parameters LaTeX uses for determining "good" float positions.
H Places the float at precisely the location in the LATEX code. Requires the float package. This is somewhat equivalent to h!.

You can put more than one value in the parameter, for instance, if you write [ht] LATEX will try to position the figure here, but if it's not possible (the space may be insufficient) then the figure will appear at the topof the page. It is recommended to use more than one positioning parameter to prevent unexpected results.

Open an example in ShareLaTeX

Multiple images in one figure

It is possible to insert several images in one figure, each one with its own reference and label

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque...
 
\begin{figure}[h]
 
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=0.9\linewidth, height=5cm]{lion-logo}
\caption{Caption1}
\label{fig:subim1}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=0.9\linewidth, height=5cm]{mesh}
\caption{Caption 2}
\label{fig:subim2}
\end{subfigure}
 
\caption{Caption for this figure with two images}
\label{fig:image2}
\end{figure}
 
Praesent blandit blandit mauris. Praesent
lectus tellus, aliquet aliquam, luctus a, egestas a, turpis. Mauris
lacinia loremsit amet ipsum. Nunc quis urna dictum turpis accumsan
semper.

First, you must import the package subcaption by adding to the preamble

\usepackage{subcaption}

then you can use the environment \subfigure that takes one parameter, the width of the figure. This environment must be used inside a figure environment, captions and labels can be set to each subfigure.

Note:The \subfigure</cont> command doesn't work with Beamer nor Beamerposter

Open an example in ShareLaTeX

Wrapping text around a figure

The package wrapfig provides a useful feature, text can be floated around the images.

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat.
 
\begin{wrapfigure}{l}{0.25\textwidth}
\includegraphics[width=0.9\linewidth]{lion-logo}
\caption{Caption1}
\label{fig:subim1}
\end{wrapfigure}
 
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum

First import the package wrapfig by adding

\usepackage{wrapfig}

to the preamble.

After that you can use the environment <code>wrapfig, it takes two parameters that are passed inside braces: the alignement that can be lrci or o; this letters stand for left, right, centre, inner and outer (the last two intended for two-sided documents). The second parameter is the width of the figure, in the example is 0.25 the width of the text. See the reference guide for a list of possible length units.

Open an example in ShareLaTeX

Positioning tables

Options for table positioning are similar to those available for figures

Basic positioning

Default position of the tabular environment is centre.

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis fringilla tristique neque. Sed interdum libero ut metus. Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit amet ante lobortis sollicitudin.
 
\arrayrulecolor[HTML]{DB5800}
\begin{tabular}{ |s|p{2cm}|p{2cm}| }
\hline
\rowcolor{lightgray} \multicolumn{3}{|c|}{Country List} \\
\hline
Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \\
\hline
Afghanistan & AF &AFG \\
\rowcolor{gray}
Aland Islands & AX & ALA \\
Albania &AL & ALB \\
Algeria &DZ & DZA \\
American Samoa & AS & ASM \\
Andorra & AD & \cellcolor[HTML]{AA0044} AND \\
Angola & AO & AGO \\
\hline
\end{tabular}
 
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Duis fringilla tristique neque. Sed interdum libero ut metus.
Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit
amet ante lobortis sollicitudin.

To learn about how to create tables see the Tables article.

Open an example in ShareLaTeX

The table environment

The table environment is intended to automatically position tables so they fit nicely in the flow of your document.

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo.
Morbi sed elit sit amet ante lobortis sollicitudin.
 
\begin{table}[ht]
\arrayrulecolor[HTML]{DB5800}
\centering
\begin{tabular}{ |s|p{2cm}|p{2cm}| }
\hline
\rowcolor{lightgray} \multicolumn{3}{|c|}{Country List} \\
\hline
Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \\
\hline
Afghanistan & AF &AFG \\
\rowcolor{gray}
Aland Islands & AX & ALA \\
Albania &AL & ALB \\
Algeria &DZ & DZA \\
American Samoa & AS & ASM \\
Andorra & AD & \cellcolor[HTML]{AA0044} AND \\
Angola & AO & AGO \\
\hline
\end{tabular}
\caption{Table inside a floating element}
\label{table:ta}
\end{table}
 
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo.
Morbi sed elit sit amet ante lobortis sollicitudin.

A position parameter, inside brackets, can be passed to the table environment. This parameter can take the next values:

Parameter Position
h Place the float here, i.e., approximately at the same point it occurs in the source text (however, not exactly at the spot)
t Position at the top of the page.
b Position at the bottom of the page.
p Put on a special page for floats only.
! Override internal parameters LaTeX uses for determining "good" float positions.
H Places the float at precisely the location in the LATEX code. Requires the float package. This is somewhat equivalent to h!.

You can set more than one value in the parameter, for instance, if you write [ht] LATEX will try to position the table here, but if it's not possible (the space may be insufficient) then the table will appear at the top of the page. It is recommended to use more than one positioning parameter to prevent unexpected results.

Notice also the command \centering. This changes the alignment of the table within its container to centreinstead of the default left.

Open an example in ShareLaTeX

Wrapping text around a table

If your table don't take all available space and you want to put text next or before it, is possible with the package wraptable.

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo.
Morbi sed elit sit amet ante lobortis sollicitudin.
 
\begin{wraptable}{r}{8cm}
\arrayrulecolor[HTML]{DB5800}
\centering
\begin{tabular}{ |s|p{2cm}| }
\hline
\rowcolor{lightgray} \multicolumn{2}{|c|}{Country List} \\
\hline
Country Name or Area Name& ISO ALPHA 2 Code \\
\hline
Afghanistan & AF \\
\rowcolor{gray}
Aland Islands & AX \\
Albania &AL \\
Algeria &DZ \\
American Samoa & AS \\
Andorra & \cellcolor[HTML]{AA0044} AD \\
Angola & AO \\
\hline
\end{tabular}
\caption{Table inside a floating element}
\label{table:ta}
\end{wraptable}
 
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo.
Morbi sed elit sit amet ante lobortis sollicitudin...

First, import the package

\usepackage{wraptable}

then you can use the environment wraptable which takes two parameters: The first one is the alignment that can be lrci or o for left, right, centre, inner and outer respectively. The second one is the width of the table container, keep in mind that this latter parameter must be the same as the width of the table, otherwise things may not be properly aligned.

Open an example in ShareLaTeX

Reference guide

LATEX units and lengths

Abbreviation Definition
pt A point, is the default length unit. About 0.3515mm
mm a millimetre
cm a centimetre
in an inch
ex the height of an x in the current font
em the width of an m in the current font
\columnsep distance between columns
\columnwidth width of the column
\linewidth width of the line in the current environment
\paperwidth width of the page
\paperheight height of the page
\textwidth width of the text
\textheight height of the text
\unitleght units of length in the picture environment.

from: https://www.sharelatex.com/learn/Positioning_images_and_tables

LaTeX排版设置图表的位置 Positioning images and tables的更多相关文章

  1. Windows下LATEX排版论文攻略—CTeX、JabRef使用介绍

    Windows下LATEX排版论文攻略—CTeX.JabRef使用介绍 一.工具介绍 TeX是一个很好排版工具,在学术界十分流行,特别是数学.物理学和计算机科学界. CTeX是TeX中的一个版本,指的 ...

  2. Latex排版全解

    Latex排版全解 LATEX(英语发音:/ˈleɪtɛk/ LAY-tek或英语发音:/ˈlɑːtɛk/ LAH-tek,音译“拉泰赫”),是一种基于TEX的排版系统,由美国电脑学家莱斯利•兰伯特在 ...

  3. 【LaTeX排版】LaTeX纸排版&lt;两&gt;

    1.文件夹的生成     直接使用命令\tableofcontents就可以. 其默认格式例如以下: 我们会发现.这种格式不一定是我们所期望的. 比方说,我们也希望章标题与页码之间也有点连线,而且也希 ...

  4. 【LaTeX排版】LaTeX论文排版<二>

    1.目录的生成     直接使用命令\tableofcontents即可.其默认格式如下: 我们会发现,这样的格式不一定是我们所期望的.比如说,我们也希望章标题与页码之间也有点连线,并且也希望将致谢. ...

  5. Eclipse的自动排版设置(format)

    Java排版:         主要是在文件保存时自动触发排版等规则,省掉反复操作快捷键 Ctrl+Shift+F 的步骤.在 eclipse 中选择 Window-> Preferences- ...

  6. 设置Toast显示位置

    设置Toast显示位置 两个方法可以设置显示位置: 方法一:setGravity(int gravity, int xOffset, int yOffset)三个参数分别表示(起点位置,水平向右位移, ...

  7. 【分享】LateX排版软件学习教程合集

    来源于:http://www.hejizhan.com/html/xueke/416/x416_13.html  LATEX2e科技排版指南.pdf 8.3 MB  An Example LaTeX ...

  8. WinForm 设置窗体启动位置在活动屏幕右下角

    WinForm 设置窗体启动位置在活动屏幕右下角 在多屏幕环境下, 默认使用鼠标所在的屏幕 1. 设置窗体的 StartPosition 为 FormStartPosition.Manual. 2. ...

  9. grid - 通过网格线名称设置网格项目位置

    使用网格线名称设置网格项目位置和使用网格线号码设置网格项目位置类似. 1.引用网格线名称的时候不应该带方括号 <view class="grid"> <view ...

随机推荐

  1. IEEEXtreme 10.0 - Counting Molecules

    这是 meelo 原创的 IEEEXtreme极限编程大赛题解 Xtreme 10.0 - Counting Molecules 题目来源 第10届IEEE极限编程大赛 https://www.hac ...

  2. 4. CMake 系列 - 项目添加编译选项

    目录 1. 项目目录结构 2. 相关代码 2.1 add 模块 2.2 sub 模块 2.3 example 模块 2.4 顶层 CMakeLists.txt 3. 配置&编译 1. 项目目录 ...

  3. google::proto::message.h

    整了一阵子google  proto message.h, 遇到很多问题,各种百度.google ,估计是用的人不是很多,整的焦头烂额,很多API都不知道该怎么用,只能一点一点的扣,为了方便在这里先简 ...

  4. VIM块操作

    一.可视模式 按v启用可视模式,之后移动光标可以选择. 如:     如果想整行操作,则用大写的V,再移动光标可以按行为单位进行选择. 二.列块操作 在 word中有一个功能,按alt加鼠标拖动,可以 ...

  5. Bzoj2002/洛谷P3203 [HNOI2010]弹飞绵羊(分块)

    题面 Bzoj 洛谷 题解 大力分块,分块大小\(\sqrt n\),对于每一个元素记一下跳多少次能跳到下一个块,以及跳到下一个块的哪个位置,修改的时候时候只需要更新元素所在的那一块即可,然后询问也是 ...

  6. centos7 默认进入系统命令行模式修改

    systemctl get-default  #查看系统启动进入默认模式 systemctl set-default graphical.target #改成默认进入 图形界面模式 systemctl ...

  7. Python入门基础知识(1) :locals() 和globals()

    Python有两个内置的函数,locals() 和globals(),它们提供了基于字典的访问局部和全局变量的方式. 首先,是关于名字空间的一个名词解释.是枯燥,但是很重要,所以要耐心些.Python ...

  8. Selenium快速入门(下)

    Frame相关 import time from selenium import webdriver from selenium.common.exceptions import NoSuchElem ...

  9. 「BZOJ 4502」串

    「BZOJ 4502」串 题目描述 兔子们在玩字符串的游戏.首先,它们拿出了一个字符串集合 \(S\),然后它们定义一个字符串为"好"的,当且仅当它可以被分成非空的两段,其中每一段 ...

  10. codevs 3160 最长公共子串 后缀自动机

    http://codevs.cn/problem/3160/ 后缀自动机板子题,匹配的时候要注意如果到一个点失配向前匹配到一个点时,此时的tmp(当前匹配值)为t[j].len+1而不是t[t[j]. ...