LaTeX Writer: Add support for customizable alignment of columns in beamer (#6331)

Add support for customizable alignment of columns in beamer.
Closes #4805, closes #4150.
This commit is contained in:
andrebauer 2020-05-03 02:08:16 +02:00 committed by GitHub
parent 0fafe9dd32
commit 97fe2ea16c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 5 deletions

View file

@ -5379,6 +5379,41 @@ containers with class `column` and a `width` attribute:
:::
::::::::::::::
### Additional columns attributes in beamer
The div containers with classes `columns` and `column` can optionally have
an `align` attribute.
The class `columns` can optionally have a `totalwidth` attribute or an
`onlytextwidth` class.
:::::::::::::: {.columns align=center totalwidth=8em}
::: {.column width="40%"}
contents...
:::
::: {.column width="60%" align=bottom}
contents...
:::
::::::::::::::
The `align` attributes on `columns` and `column` can be used with the
values `top`, `top-baseline`, `center` and `bottom` to vertically align
the columns. It defaults to `top` in `columns`.
The `totalwidth` attribute limits the width of the columns to the given value.
:::::::::::::: {.columns align=top .onlytextwidth}
::: {.column width="40%" align=center}
contents...
:::
::: {.column width="60%"}
contents...
:::
::::::::::::::
The class `onlytextwidth` sets the `totalwidth` to `\textwidth`.
See Section 12.7 of the [Beamer User's Guide] for more details.
## Frame attributes in beamer
Sometimes it is necessary to add the LaTeX `[fragile]` option to

View file

@ -1031,6 +1031,14 @@ sectionHeader classes ident level lst = do
braces txtNoNotes
else empty
mapAlignment :: Text -> Text
mapAlignment a = case a of
"top" -> "T"
"top-baseline" -> "t"
"bottom" -> "b"
"center" -> "c"
_ -> a
wrapDiv :: PandocMonad m => Attr -> Doc Text -> LW m (Doc Text)
wrapDiv (_,classes,kvs) t = do
beamer <- gets stBeamer
@ -1038,14 +1046,25 @@ wrapDiv (_,classes,kvs) t = do
lang <- toLang $ lookup "lang" kvs
let wrapColumns = if beamer && "columns" `elem` classes
then \contents ->
inCmd "begin" "columns" <> brackets "T"
$$ contents
$$ inCmd "end" "columns"
let valign = maybe "T" mapAlignment (lookup "align" kvs)
totalwidth = maybe [] (\x -> ["totalwidth=" <> x])
(lookup "totalwidth" kvs)
onlytextwidth = filter ((==) "onlytextwidth") classes
options = text $ T.unpack $ T.intercalate "," $
valign : totalwidth ++ onlytextwidth
in inCmd "begin" "columns" <> brackets options
$$ contents
$$ inCmd "end" "columns"
else id
wrapColumn = if beamer && "column" `elem` classes
then \contents ->
let w = maybe "0.48" fromPct (lookup "width" kvs)
in inCmd "begin" "column" <>
let valign =
maybe ""
(brackets . text . T.unpack . mapAlignment)
(lookup "align" kvs)
w = maybe "0.48" fromPct (lookup "width" kvs)
in inCmd "begin" "column" <>
valign <>
braces (literal w <> "\\textwidth")
$$ contents
$$ inCmd "end" "column"

View file

@ -0,0 +1,40 @@
```
pandoc -t beamer
:::: { .columns }
::: { .column align=center }
:::
::: { .column align=bottom }
:::
::::
:::: { .columns align=bottom .onlytextwidth }
::: { .column align=top }
:::
::: { .column align=top-baseline }
:::
::::
:::: { .columns totalwidth=7em }
::::
^D
\begin{frame}
\begin{columns}[T]
\begin{column}[c]{0.48\textwidth}
\end{column}
\begin{column}[b]{0.48\textwidth}
\end{column}
\end{columns}
\begin{columns}[b,onlytextwidth]
\begin{column}[T]{0.48\textwidth}
\end{column}
\begin{column}[t]{0.48\textwidth}
\end{column}
\end{columns}
\begin{columns}[T,totalwidth=7em]
\end{columns}
\end{frame}
```