简体   繁体   中英

How to change the chart title width to match slide width in python-pptx?

Hi I have simple code which generates one ppt slide like below but the slide title width is smaller than slide width? how can I increase the title width?

在此处输入图像描述

from pptx.util import Inches, Pt
from pptx import Presentation

prs = Presentation()
prs.slide_width = Inches(16)
prs.slide_height = Inches(9)
blank_slide_layout = prs.slide_layouts[5]
slide = prs.slides.add_slide(blank_slide_layout)
title = slide.shapes.title

title.text = "This is test slide.This is test slide.This is test slide.This is test slide.This is test slide.This is test slide"
title.text_frame.paragraphs[0].font.size = Pt(20)

prs.save('test.pptx')

The position and size of the slide title is normally determined by the slide layout. In this case you seem to have chosen the one layout which does not have a title shape.

I would start by using a different slide layout, like slide_layouts[1] and see if the title isn't closer to what you want.

The benefit of using the slide layout for that job is that all slides created with that layout have a consistently positioned and formatted title with no extra work on your part. It also has benefits for when you change templates.

Otherwise, if you really want to adjust the size in a particular case, slide.shapes.title is a shape, and has .left , .top , .width , and .height properties like any other shapes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM