File: subfigure.py

package info (click to toggle)
python-pylatex 1.4.2%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,044 kB
  • sloc: python: 3,810; sh: 209; makefile: 169; xml: 12
file content (32 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
"""
This example shows subfigure functionality.

..  :copyright: (c) 2014 by Jelte Fennema.
    :license: MIT, see License for more details.
"""

# begin-doc-include
import os

from pylatex import Document, Figure, NoEscape, Section, SubFigure

if __name__ == "__main__":
    doc = Document(default_filepath="subfigures")
    image_filename = os.path.join(os.path.dirname(__file__), "kitten.jpg")

    with doc.create(Section("Showing subfigures")):
        with doc.create(Figure(position="h!")) as kittens:
            with doc.create(
                SubFigure(position="b", width=NoEscape(r"0.45\linewidth"))
            ) as left_kitten:
                left_kitten.add_image(image_filename, width=NoEscape(r"\linewidth"))
                left_kitten.add_caption("Kitten on the left")
            with doc.create(
                SubFigure(position="b", width=NoEscape(r"0.45\linewidth"))
            ) as right_kitten:
                right_kitten.add_image(image_filename, width=NoEscape(r"\linewidth"))
                right_kitten.add_caption("Kitten on the right")
            kittens.add_caption("Two kittens")

    doc.generate_pdf(clean_tex=False)