Open eijoac opened 6 years ago
For the pdf version you can use the fig.pos
chunk option to use figures (not sure about other margin elements). For example, fig.pos="4cm"
moves a margin figure 4 cm down (negative values move it up).
Hi, I'm having the same issue. It looks like it is vertically center-aligned rather than top-aligned to the next line. Since I was planning to use this a lot, I was wondering whether anyone had some sort of general workaround (each of my many images will have a different size, and retouching the position of all of them looks like a nightmare to maintain... even just changing a caption destroys the alignment...)
For me this issue is fixed with the code in the accepted answer here: https://tex.stackexchange.com/questions/193137/modify-the-tuftemarginfloat-environment-to-automatically-align-floats
I'm experiencing this same issue. Unfortunately, the suggested workarounds are not fixing the problem. For example, using the fig.pos
chunk option requires manual adjustment for each figure and is not maintainable for documents with many figures. On the other hand, the LaTeX solution suggested in (https://github.com/rstudio/tufte/issues/62#issuecomment-725731888) relies on hardcoded values and doesn't behave well with subsequent figures. It also doesn't align correctly in many cases.
As the package heavily relies on these margin figures, any code blocks exceeding a few lines, such as those commonly used with ggplot, make the alignment issues more noticeable.
This is my minimal reproducible example:
---
title: "An Example Using the Tufte Style"
output:
tufte::tufte_handout:
latex_engine: xelatex
---
# Load required libraries
'''{r setup}
library(dplyr)
library(ggplot2)
library(tufte)
'''
## Test
'''{r, fig.margin = TRUE}
# Load the mtcars dataset
data(mtcars)
# Create a scatter plot
ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
geom_point(size = 3, alpha = 0.7) +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Car Weight vs. MPG by Number of Cylinders",
x = "Weight (1000 lbs)",
y = "Miles per Gallon",
color = "Cylinders") +
theme_minimal() +
scale_color_brewer(palette = "Set1")
'''
The Tufte pdf handout rendering seems to have an issue aligning 'margin figure' and main text. I believe the top of the 'margin figure' should align with the first line of the text after the {marginfigure} markdown block, but it doesn't. The html rendering is good. (i am not sure whether this is a pandoc problem or tufte package problem though.)
pdf (not correct)
html (good)