Pandoc Markdown到PDF图像位置

时间:2018-03-25 23:55:39

标签: pdf markdown pandoc

使用pandoc将Markdown文档转换为PDF时,我的图像不会放在我将它们放在源代码中的相同位置。我相信这是由于通过LaTeX的转换,但我不确定如何在Markdown源中解决这个问题。

如果我使用带有多段示例文本的占位符图像并将图像策略性地放置在源代码中,它会变得太大而无法放在我放置它的位置的页面上,因此LaTeX布局引擎可以放置它在下一页。但是,我宁愿这没有发生,因为这意味着图像不是我所期望的,并且更难以引用。

如果有必要,我可以提供一个例子,但重现这一点很简单,并且源需要有点广泛才能填满整个页面。

3 个答案:

答案 0 :(得分:10)

您是否尝试停用

中的implicit_figures
pandoc -f markdown-implicit_figures -t pdf myfile.md

要解决尺寸问题,您还可以尝试使用属性修复markdown文件中的尺寸。这样的事情可以做到这一点:

![Caption text](/path/to/image){ width=50% }

答案 1 :(得分:1)

尽管Bruno的将数字强制到指定位置的解决方案是可行的,但它也从结果的$request->input("project_id")中删除了.image{ height: 150px; width: 600px; } 文件中指定的标题

为防止数字浮动但保留标题:

1。创建一个包含以下内容的@media( max-width: 600px){ .image{ width:100vw; height: 25vw; } } 文件:

<?php
session_start();
$con=mysqli_connect("localhost","root");
mysqli_select_db($con,'login');

$name=$_POST['username'];
$pass=$_POST['password'];

$s="select * from users where username = '$name' && password = '$pass'";
$result=mysqli_query($con,$s);
$num=mysqli_num_rows($result);

if($num==1){
    echo('<script>alert("Login Success!!")</script>');
    header("Location:homepage.php");
}
else{
    echo('<script>alert("No user found!!")</script>');
    header("Location:process.php");
}
?>

这将防止LaTeX浮动图形。

2。调整pandoc呼叫

假设您已命名新创建的.md文件.pdf,只需将.tex添加到您的\usepackage{float} \let\origfigure\figure \let\endorigfigure\endfigure \renewenvironment{figure}[1][2] { \expandafter\origfigure\expandafter[H] } { \endorigfigure } 调用中:

.tex

在SO上支持this answer,在github上支持this comment

答案 2 :(得分:0)

实现相同结果的@apitsch 答案的替代方法:文本中调用的图像(尽管不完全与文本“内嵌”),带有标题。

这样做:

  • 在您的 pandoc --include-in-header 模板(@apitsch 的回答中的 disable_float.tex)中使用,而不是

    % Override default figure placement To be within the flow of the text rather
    % than on it's own page.
    \usepackage{float}
    \makeatletter
    \def\fps@figure{H} 
    \makeatother
    

    其他默认定位方案见:https://www.overleaf.com/learn/latex/Inserting_Images#Positioning。例如。您可以指定 H 代替 t

  • 在您的 Markdown 源代码中,您可能还想指定一个高度属性。在乳胶上下文中,这是 \textheight 的高度(几乎是页面的高度)。

    ![Caption for my image](MyImage.jpg){height=55%}