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)
Fixed! just added the two lines below:
doc.packages.append(Package('adjustbox'))
doc.append(NoEscape(r'\begin{adjustbox}{width=1\textwidth}'))
doc.append(NoEscape(df.describe().to_latex()))
doc.append(NoEscape(r'\end{adjustbox}'))
Best Answer
(Note: I've never heard of
pylatex
before, so this answer is just based on looking at the example in the documentation.)Depends on what you need, and how you want to print it. The simplest case would be to just print the values in the
DataFrame
as a matrix. Or you could just build a table.The example below generates this: