How can I place two images side-by-side with Asciidoctor? - asciidoc

I'm trying to place two images side-by-side, and ideally center the whole block in an Asciidoctor project. The code below works in the HTML5 output, but stacks the images when rendered to a PDF.
[.clearfix]
--
[.left]
.Title1
image::chapter3/images/foo.png[Foo, 450, scaledwidth="75%"]
[.left]
.Title2
image::chapter3/images/bar.png[Bar, 450, scaledwidth="75%"]
--
Is it possible to 1) render side-by-side images in a PDF and 2) center the block of images? If it's possible to specify the space between them, that would be great too.
Thanks,
Matt

Not sure if you can specify the space between them, but you're using the block image instead of the inline (image::...[] vs image:..[], note the colons). I'm also not sure how centring works in pdf as I don't do a lot of pdf generation, but if those are the only things on that line, they may center, or maybe a .center would do it?

1) render side-by-side images in a PDF
Yes. Following eskwayrd answer for Asciidoctor: how to layout two code blocks side by side? you can insert your image inside a table with only 2 columns.
[cols="a,a"]
|===
| image::foo.png[]
| image::bar.png[]
|===
I would in your case even completely hide the table
[cols="a,a", frame=none, grid=none]
|===
| image::foo.png[]
| image::bar.png[]
|===
2) center the block of images
This is currently complicated in PDF.
Well our block is now a table so we have a few options in HTML. Aligning the content with < and > is simple enough and works.
[cols=">a,<a", frame=none, grid=none]
|===
| image::foo.png[]
| image::bar.png[]
|===
Setting the table width to automatic and centering it also works in HTML:
[%autowidth, cols="a,a", frame=none, grid=none, role="center"]
|===
| image::foo.png[]
| image::bar.png[]
|===
These two methods however, for some reason, do not work in PDF when converting with asciidoctor-pdf. One "solution" for PDF would be to expand your table with extra empty columns left and right and trying to adjust their width with integers.
[cols="3,1a,1a,3", frame=none, grid=none]
|===
|
| image::foo.png[]
| image::bar.png[]
|
|===

Related

Asciidoc split first table header cell

I have following table in asciidoc, for which I want the very first cell to be split diagonally (or by some other means more readable) in the sense that it is clear that the top row is the "to", the first column is the "from" one:
[cols=","]
|===
a|
To →
From ↓
|Hans
|Karl
|Secret gift
|===
Please note that if I change to [cols=",",options="header"] the spaces of the first cell are removed, making it even harder to understand the table semantics.
See also How can a split diagonally a table header cell? for similar question explaining the requirement in HTML
You would need custom CSS, and possibly a background image, to perform the diagonal split that you seek.
However, built-in roles might suffice:
[cols="a,"]
|===
h|
[.right]#to →#
From ↓
|Hans
|Karl
|Secret gift
|===
This makes the "to/from" cell a header, and uses the default theme's .right style to move the "to" to the right edge of the cell.
If you do need to apply custom styles, see the section on Docinfo Files.
The answers to this question might provide an appropriate solution for you.

PDF and Word extraction of text overlaid on images

Tools used for processing content from PDF or Microsoft Word (DOC, DOCX), when parsing documents with images that have text labels overlaid on them, extract these labels separately to the images. The result is each such image being extracted without the overlaid text and then followed by one or more paragraphs of that text, out of context.
In such cases, an image like (a)
-------------
| Level 2 |
-------------
| Level 1 |
-------------
is extracted as (b)
-------------
| |
-------------
| |
-------------
Level 2
Level 1
This is "standard" behavior for tools used for PDF or Word processing, like Apache PDFBox and POI.
Is there any way of handling this, in the Apache tools, or any other similar tool?
The ideal solution would be to extract both the image and the labels as a single entity, like (a) above. Alternatively, image and label extraction could be deactivated together.
Ultimately, there should be way for avoiding the "pollution" of the document text with the labels, which otherwise appear out of content.

asciidoc empty table rows

I like to have a table in asciidoc, where there is an empty row in it.
The problem is, letting the row empty makes it very small automatically.
[cols="5,3,3"]
|===
|||
|===
I tried to fill the cells with spaces, + `s , line feeds, tabs. But there is no character I know, where the cell is empty on the paper and has the normal height.
What I mean is a css-like min-height, or a special character like in html.
So how to force an empty table row to have the normal line height?
Your problem seems difficult. I hope you have good reasons to add an empty row.
Maybe a small hack might help you for the moment :-)
[cols="5,3,3"]
|===
a|image:sunset.jpg[""]||
|===
I just put an image which does not exists in the first column. Maybe a one pixel image might work as well. The a in front of |makes the asciidoctor interpreter to read it as asciidoctor.
Found the solution by myself:
[cols="5a,3,3"]
|===
|{nbsp} +
{nbsp} +||
|===
The ain the column definition marks this column as asciidoc-content, so that asciidoc commands will work. The {nbsp} + is the magic keyword for an empty space, which is not like the normal space. The normal space will be ignored, the {nbsp} is not ignored.
Hope that helps for other cases too.
Found it here: https://github.com/asciidoctor/asciidoctor/wiki/How-to-insert-sequential-blank-lines

LibreOffice Calc two Alignments - One Cell

Is it possible to write one word with left alignment and one word with right alignment in a single cell in LibreOffice Calc?
Like that: | normal Cell one | Halli _________ Hallo | normal Cell three |
Everytime I try to simulate it with many spaces between Halli and Hallo, there are format problems when I convert it to PDF.
Format the cell to have a distributed horizontal alignment [my LO 4.1.6.2 on Linux offer this option].
Stayed that way after exporting to PDF.
This is not a programming question - use SuperUser for software handling questions next time, please.

How to use Pandoc image alignment to align two images in the same row?

From the pandoc documentation I know how to insert an image
http://johnmacfarlane.net/pandoc/README.html#images
Now I want to align two images in the same row, how can I do that?
My desired output format is pdf.
You can try something like this:
![](tests/lalune.jpg)\ ![](tests/lalune.jpg)
This will give you two side-by-side images. You won't have a caption, though; pandoc only treats an image as a captioned figure if it is by itself in a paragraph.
Expanding on from John's answer, if you do want a single caption under two side by side figures, a 'hack' would be to do this:
![](https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png){width=60%}
![](https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png){width=40%}
\begin{figure}[!h]
\caption{A single caption for the two subfigures}
\end{figure}
This results in one caption for two images placed side by side. You might need to tweak each individual image's width setting, or the !h caption placement specifier to get things looking like this:
I found this helpful because you don't have to download the picture off the internet as in a pure LaTeX \subfigure solution. I.e. just use pandoc markdown to get the image, and LaTeX to generate the caption.
If you want to go crazy, you can actually use the same idea above to make subfigure captions like so:
![](https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png){width=60%}
![](https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png){width=40%}
\begin{figure}[!h]
\begin{subfigure}[t]{0.6\textwidth}
\caption{Caption for the left subfigure}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.4\textwidth}
\caption{Caption for the right subfigure}
\end{subfigure}
\caption{A single caption for the two subfigures}
\end{figure}
Edit 20180910:
You'll need to include the following packages in the pandoc YAML frontmatter/header:
header-includes: |
\usepackage{caption}
\usepackage{subcaption}
One simple way is convert your file first to a .tex file, where you can adjust your image alignment with LaTeX command minipage or so. Then you could obtain your .pdf file running latex or pandoc in command line. See Pandoc Demos for example.
You could use a preprocessor like gpp to include options like align image. Or you could do it like how John told you:
![](tests/lalune.jpg)\ ![](tests/lalune.jpg)

Resources