Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{marginfigure} and main text alignment issue #62

Open
eijoac opened this issue Oct 1, 2018 · 4 comments
Open

{marginfigure} and main text alignment issue #62

eijoac opened this issue Oct 1, 2018 · 4 comments

Comments

@eijoac
Copy link

eijoac commented Oct 1, 2018

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)

image

html (good)

image

@singmann
Copy link

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).

@danieleghisi
Copy link

danieleghisi commented Apr 2, 2020

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...)

@zenzike
Copy link

zenzike commented Nov 12, 2020

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

@r-3141592-pi
Copy link

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 (#62 (comment)) 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")
'''

screenshot-240910-1541-01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants