You need to change the pylatex.Document
arguments to:
doc = pylatex.Document('basic',font_size = '', inputenc = 'utf8x', lmodern = False, fontenc = None, textcomp = None)
in order to remove the normalsize
line.
To put the fontselect
in place a command for it after the command for fontsize
like this:
doc.append(pylatex.Command('fontsize', arguments = ['15', '12']))
doc.append(pylatex.Command('selectfont'))
The font size will then be 15.
The position
for a subfigure
is not related to horizontal positioning, but vertical positioning. It determines how the subfigure
is placed on the baseline.
What you should do instead is to import Command
from pylatex
, and then add
doc.append(Command('centering'))
at the start of each figure.
In addition you should remove placement='c'
from the image inclusion, which doesn't do anything, except adding a c
to your document.
# the picture to plot
# [![kitten][1]][1]
# my code
import os
from pylatex import Document, PageStyle, NewPage, SubFigure, Figure, Section, Command
from pylatex.utils import NoEscape
def generate_pdf_report(imageFilename):
geometry_options = { "head": "30pt",
"margin": "0.3in",
"top": "0.2in",
"bottom": "0.4in",
"includeheadfoot": True}
doc = Document(geometry_options=geometry_options)
first_page = PageStyle("firstpage")
doc.preamble.append(first_page)
doc.change_document_style("firstpage")
with doc.create(Section('Plotting multiple figures')):
doc.append("How to set the pictures at center of page without change the width?")
with doc.create(Figure(position='h!')) as imagesRow1:
doc.append(Command('centering'))
with doc.create(
SubFigure(position='c', width=NoEscape(r'0.33\linewidth'))) as left_imagesRow1:
left_imagesRow1.add_image(imageFilename, width=NoEscape(r'0.95\linewidth'))
left_imagesRow1.add_caption("img 1")
with doc.create(
SubFigure(position='c', width=NoEscape(r'0.33\linewidth'))) as right_imagesRow1:
right_imagesRow1.add_image(imageFilename, width=NoEscape(r'0.95\linewidth'))
right_imagesRow1.add_caption("img 2")
with doc.create(Figure(position='h!')) as imagesRow2:
doc.append(Command('centering'))
with doc.create(
SubFigure(position='c', width=NoEscape(r'0.33\linewidth'))) as left_imagesRow2:
left_imagesRow2.add_image(imageFilename, width=NoEscape(r'0.95\linewidth'))
left_imagesRow2.add_caption("img 3")
with doc.create(
SubFigure(position='c', width=NoEscape(r'0.33\linewidth'))) as right_imagesRow2:
right_imagesRow2.add_image(imageFilename, width=NoEscape(r'0.95\linewidth'))
right_imagesRow2.add_caption("img 4")
imagesRow2.add_caption("Setting the subpictures at center")
doc.append(NewPage())
doc.generate_pdf("test_image_positions", compiler="pdflatex", clean=True, clean_tex=False)
imageFilename = os.path.join(os.getcwd(),"out-inc.pdf")
generate_pdf_report( imageFilename)
Best Answer
Constructor
Document
does not support options for the document class. However, thedocumentclass
is available asCommand
and can be overwritten:Also a package like
geometry
can be added, see the following example, which was derived from the basic and full example of the documentation ofpylatex
: