Automatic positioning of images and tables in PowerPoint slide officer
Hi so I have I am trying to write my own function that will automatically size and central align the images/tables that I am generating from officer.
The top/left functions in the add_image and add_table are good when I add each table manually as The differing tables are differing sizes but I wasn't sure how to automatically do it for different shaped images and tables.
I have the following code for images:
Image <- function(PP,title,footer,pageNO,path){
im <- load.image(path)
width <- imager::width(im)
height <- imager::height(im)
ratio <- width/height
if(ratio < 9.15 / 3.6){
y <- 3.6
x <- 3.6 * ratio
}
if(ratio >= 9.15 / 3.6){
y <- 9.15 / ratio
x <- 9.15
}
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_img(type = "body", src = path, height = y, width = x) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "sldNum", str = pageNO)
}
I would then like to align this image in the centre of the slide but am not sure how I would do this.
Then the same for tables but I have no idea how to do this as I would have to automatically rescale the width and height of columns based on original width and height of the flextable image as I wouldn't want to lose the aspect ratio unless there is a different way?
Current code for this is: but it doesn't do any resizing:
Slide <- function(PP,title,footer,pageNO,table){
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_flextable(value = table, type = "body") %>%
ph_with_text(type = "sldNum", str = pageNO)
}
Many thanks in advance, any help would be greatly appreciated
r flextable officer
|
show 1 more comment
Hi so I have I am trying to write my own function that will automatically size and central align the images/tables that I am generating from officer.
The top/left functions in the add_image and add_table are good when I add each table manually as The differing tables are differing sizes but I wasn't sure how to automatically do it for different shaped images and tables.
I have the following code for images:
Image <- function(PP,title,footer,pageNO,path){
im <- load.image(path)
width <- imager::width(im)
height <- imager::height(im)
ratio <- width/height
if(ratio < 9.15 / 3.6){
y <- 3.6
x <- 3.6 * ratio
}
if(ratio >= 9.15 / 3.6){
y <- 9.15 / ratio
x <- 9.15
}
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_img(type = "body", src = path, height = y, width = x) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "sldNum", str = pageNO)
}
I would then like to align this image in the centre of the slide but am not sure how I would do this.
Then the same for tables but I have no idea how to do this as I would have to automatically rescale the width and height of columns based on original width and height of the flextable image as I wouldn't want to lose the aspect ratio unless there is a different way?
Current code for this is: but it doesn't do any resizing:
Slide <- function(PP,title,footer,pageNO,table){
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_flextable(value = table, type = "body") %>%
ph_with_text(type = "sldNum", str = pageNO)
}
Many thanks in advance, any help would be greatly appreciated
r flextable officer
1
The solution I've been using is to just specify theleft
(left offset argument) as(slide_width - img_width)/2
manually, which centers the image horizontally (same idea for vertically)
– IceCreamToucan
Jan 2 at 18:56
That seems like a good option, I will try implementing that :), thanks for your response - How would you look at doing it for tables?
– Zuti
Jan 3 at 14:26
I tried that and it didn't seem to work, changed thje line to this: ph_with_img(type = "body", src = path, height = y, width = x,left = (slide_width - img_width)/2) and it gave me this error message: Error in ph_with_img(., type = "body", src = path, height = y, width = x, : unused argument (left = (slide_width - img_width)/2) where this was defined as left = (9.15 - x)/2) @IceCreamToucan
– Zuti
Jan 3 at 14:36
See?ph_with_img
.ph_with_img_at
is the one with aleft
argument
– IceCreamToucan
Jan 3 at 14:40
Thanks - I've got it working now - just need to tinker around with the height as my slide isn't identical at top and bottom - thanks I appreciate your help
– Zuti
Jan 3 at 15:05
|
show 1 more comment
Hi so I have I am trying to write my own function that will automatically size and central align the images/tables that I am generating from officer.
The top/left functions in the add_image and add_table are good when I add each table manually as The differing tables are differing sizes but I wasn't sure how to automatically do it for different shaped images and tables.
I have the following code for images:
Image <- function(PP,title,footer,pageNO,path){
im <- load.image(path)
width <- imager::width(im)
height <- imager::height(im)
ratio <- width/height
if(ratio < 9.15 / 3.6){
y <- 3.6
x <- 3.6 * ratio
}
if(ratio >= 9.15 / 3.6){
y <- 9.15 / ratio
x <- 9.15
}
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_img(type = "body", src = path, height = y, width = x) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "sldNum", str = pageNO)
}
I would then like to align this image in the centre of the slide but am not sure how I would do this.
Then the same for tables but I have no idea how to do this as I would have to automatically rescale the width and height of columns based on original width and height of the flextable image as I wouldn't want to lose the aspect ratio unless there is a different way?
Current code for this is: but it doesn't do any resizing:
Slide <- function(PP,title,footer,pageNO,table){
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_flextable(value = table, type = "body") %>%
ph_with_text(type = "sldNum", str = pageNO)
}
Many thanks in advance, any help would be greatly appreciated
r flextable officer
Hi so I have I am trying to write my own function that will automatically size and central align the images/tables that I am generating from officer.
The top/left functions in the add_image and add_table are good when I add each table manually as The differing tables are differing sizes but I wasn't sure how to automatically do it for different shaped images and tables.
I have the following code for images:
Image <- function(PP,title,footer,pageNO,path){
im <- load.image(path)
width <- imager::width(im)
height <- imager::height(im)
ratio <- width/height
if(ratio < 9.15 / 3.6){
y <- 3.6
x <- 3.6 * ratio
}
if(ratio >= 9.15 / 3.6){
y <- 9.15 / ratio
x <- 9.15
}
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_img(type = "body", src = path, height = y, width = x) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "sldNum", str = pageNO)
}
I would then like to align this image in the centre of the slide but am not sure how I would do this.
Then the same for tables but I have no idea how to do this as I would have to automatically rescale the width and height of columns based on original width and height of the flextable image as I wouldn't want to lose the aspect ratio unless there is a different way?
Current code for this is: but it doesn't do any resizing:
Slide <- function(PP,title,footer,pageNO,table){
PP <- PP %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_with_text(type = "title", str = title) %>%
ph_with_text(type = "ftr",str = footer) %>%
ph_with_text(type = "dt", str = format(Sys.Date())) %>%
ph_with_flextable(value = table, type = "body") %>%
ph_with_text(type = "sldNum", str = pageNO)
}
Many thanks in advance, any help would be greatly appreciated
r flextable officer
r flextable officer
asked Jan 2 at 14:47
ZutiZuti
156
156
1
The solution I've been using is to just specify theleft
(left offset argument) as(slide_width - img_width)/2
manually, which centers the image horizontally (same idea for vertically)
– IceCreamToucan
Jan 2 at 18:56
That seems like a good option, I will try implementing that :), thanks for your response - How would you look at doing it for tables?
– Zuti
Jan 3 at 14:26
I tried that and it didn't seem to work, changed thje line to this: ph_with_img(type = "body", src = path, height = y, width = x,left = (slide_width - img_width)/2) and it gave me this error message: Error in ph_with_img(., type = "body", src = path, height = y, width = x, : unused argument (left = (slide_width - img_width)/2) where this was defined as left = (9.15 - x)/2) @IceCreamToucan
– Zuti
Jan 3 at 14:36
See?ph_with_img
.ph_with_img_at
is the one with aleft
argument
– IceCreamToucan
Jan 3 at 14:40
Thanks - I've got it working now - just need to tinker around with the height as my slide isn't identical at top and bottom - thanks I appreciate your help
– Zuti
Jan 3 at 15:05
|
show 1 more comment
1
The solution I've been using is to just specify theleft
(left offset argument) as(slide_width - img_width)/2
manually, which centers the image horizontally (same idea for vertically)
– IceCreamToucan
Jan 2 at 18:56
That seems like a good option, I will try implementing that :), thanks for your response - How would you look at doing it for tables?
– Zuti
Jan 3 at 14:26
I tried that and it didn't seem to work, changed thje line to this: ph_with_img(type = "body", src = path, height = y, width = x,left = (slide_width - img_width)/2) and it gave me this error message: Error in ph_with_img(., type = "body", src = path, height = y, width = x, : unused argument (left = (slide_width - img_width)/2) where this was defined as left = (9.15 - x)/2) @IceCreamToucan
– Zuti
Jan 3 at 14:36
See?ph_with_img
.ph_with_img_at
is the one with aleft
argument
– IceCreamToucan
Jan 3 at 14:40
Thanks - I've got it working now - just need to tinker around with the height as my slide isn't identical at top and bottom - thanks I appreciate your help
– Zuti
Jan 3 at 15:05
1
1
The solution I've been using is to just specify the
left
(left offset argument) as (slide_width - img_width)/2
manually, which centers the image horizontally (same idea for vertically)– IceCreamToucan
Jan 2 at 18:56
The solution I've been using is to just specify the
left
(left offset argument) as (slide_width - img_width)/2
manually, which centers the image horizontally (same idea for vertically)– IceCreamToucan
Jan 2 at 18:56
That seems like a good option, I will try implementing that :), thanks for your response - How would you look at doing it for tables?
– Zuti
Jan 3 at 14:26
That seems like a good option, I will try implementing that :), thanks for your response - How would you look at doing it for tables?
– Zuti
Jan 3 at 14:26
I tried that and it didn't seem to work, changed thje line to this: ph_with_img(type = "body", src = path, height = y, width = x,left = (slide_width - img_width)/2) and it gave me this error message: Error in ph_with_img(., type = "body", src = path, height = y, width = x, : unused argument (left = (slide_width - img_width)/2) where this was defined as left = (9.15 - x)/2) @IceCreamToucan
– Zuti
Jan 3 at 14:36
I tried that and it didn't seem to work, changed thje line to this: ph_with_img(type = "body", src = path, height = y, width = x,left = (slide_width - img_width)/2) and it gave me this error message: Error in ph_with_img(., type = "body", src = path, height = y, width = x, : unused argument (left = (slide_width - img_width)/2) where this was defined as left = (9.15 - x)/2) @IceCreamToucan
– Zuti
Jan 3 at 14:36
See
?ph_with_img
. ph_with_img_at
is the one with a left
argument– IceCreamToucan
Jan 3 at 14:40
See
?ph_with_img
. ph_with_img_at
is the one with a left
argument– IceCreamToucan
Jan 3 at 14:40
Thanks - I've got it working now - just need to tinker around with the height as my slide isn't identical at top and bottom - thanks I appreciate your help
– Zuti
Jan 3 at 15:05
Thanks - I've got it working now - just need to tinker around with the height as my slide isn't identical at top and bottom - thanks I appreciate your help
– Zuti
Jan 3 at 15:05
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008360%2fautomatic-positioning-of-images-and-tables-in-powerpoint-slide-officer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008360%2fautomatic-positioning-of-images-and-tables-in-powerpoint-slide-officer%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The solution I've been using is to just specify the
left
(left offset argument) as(slide_width - img_width)/2
manually, which centers the image horizontally (same idea for vertically)– IceCreamToucan
Jan 2 at 18:56
That seems like a good option, I will try implementing that :), thanks for your response - How would you look at doing it for tables?
– Zuti
Jan 3 at 14:26
I tried that and it didn't seem to work, changed thje line to this: ph_with_img(type = "body", src = path, height = y, width = x,left = (slide_width - img_width)/2) and it gave me this error message: Error in ph_with_img(., type = "body", src = path, height = y, width = x, : unused argument (left = (slide_width - img_width)/2) where this was defined as left = (9.15 - x)/2) @IceCreamToucan
– Zuti
Jan 3 at 14:36
See
?ph_with_img
.ph_with_img_at
is the one with aleft
argument– IceCreamToucan
Jan 3 at 14:40
Thanks - I've got it working now - just need to tinker around with the height as my slide isn't identical at top and bottom - thanks I appreciate your help
– Zuti
Jan 3 at 15:05