I have started to use the tikzposter
class and I wonder why the text inside blocks is flushed left by default instead of justified. How can I change the text alignment in blocks to be fully justified?
[Tex/LaTex] tikzposter text justification in blocks
tikz-pgftikzposter
Related Solutions
I ended up solving it myself. Below is the code I used; if you put it in myposter.sty
then use \usepackage[colalign]{myposter}
to enable the alignment.
It works by saving the natural heights of all columns into the aux file, along with how many blocks there are. Then next compilation, for each column, it looks at the difference between the stored height and the maximum stored height, divides that by the number of blocks, and adds that much padding inside each block (at the top and bottom.)
\usepackage{letltxmacro}
\usepackage{ifthen}
\newif\ifmy@colalign
\my@colalignfalse
\DeclareOption{colalign}{
\my@colaligntrue
}
\ProcessOptions\relax
\ifmy@colalign
% Align the bottoms of columns
% Declarations
\newcounter{my@column}
\newcounter{my@column@loop}
\newcounter{my@block}
\newdimen\my@columnextraspace
\newdimen\my@maxcolheight
\newdimen\my@colheight
\newdimen\my@blocktopstart
\newdimen\my@rounded
% Store the natural height and number of blocks of the current column in the aux file
\gdef\my@storecolheight{
\ifnum\value{my@column} > 0 %
\expandafter\newdimen\csname my@colheight\alph{my@column}\endcsname
\expandafter\setlength\csname my@colheight\alph{my@column}\endcsname{\my@colheight}
\immediate\write\@auxout{\noexpand\newlabel{my@colheight\alph{my@column}}{{\the\my@colheight}{}}}
\immediate\write\@auxout{\noexpand\newlabel{my@numblocks\alph{my@column}}{{\the\c@my@block}}}
\fi
}
\LetLtxMacro{\orig@block}{\block}
% Replace the \block command with a version that pads each block by \my@columnextraspace
\renewcommand{\block}[3][]{%
\ifTP@columnEnvironment
\my@blocktopstart=0pt\relax
\advance\my@blocktopstart-\TP@blocktop
\fi
\orig@block[{#1}]{#2}{\vspace*{-0.5\my@columnextraspace}#3\vspace*{-0.5\my@columnextraspace}}
\ifTP@columnEnvironment
% count number of blocks
\stepcounter{my@block}
% keep track of the height of the current column
\advance\my@blocktopstart\TP@blocktop
\advance\my@colheight\my@blocktopstart
% don't add the padding to the height
\advance\my@colheight-\my@columnextraspace
\fi
}
% Store the maximum natural height of any column in the aux file
\gdef\my@storemaxcolheight{
\ifnum\value{my@column} > 0 %
\newdimen\my@maxcolheight
\newdimen\my@colheight@loop
\setcounter{my@column@loop}{0}
\loop\ifnum\value{my@column@loop}<\value{my@column}
\stepcounter{my@column@loop}
\my@colheight@loop\csname my@colheight\alph{my@column@loop}\endcsname
\ifnum\my@colheight@loop<\my@maxcolheight
\my@maxcolheight\my@colheight@loop
\fi
\repeat
\immediate\write\@auxout{\noexpand\newlabel{my@maxcolheight}{{\the\my@maxcolheight}{}}}
\fi
}
% Read the column height information and calculate how much extra space the current column needs per block
\gdef\my@calcextraspace{
\@ifundefined{r@my@maxcolheight}{%
\my@columnextraspace=0pt\relax
}{%
\expandafter\my@maxcolheight\ref{my@maxcolheight}
\expandafter\my@colheight\ref{my@colheight\alph{my@column}}
\setcounter{my@block}{\ref{my@numblocks\alph{my@column}}}
\my@columnextraspace\my@maxcolheight
\advance\my@columnextraspace-\my@colheight
\divide\my@columnextraspace by \value{my@block}
}
}
% Replace \column command by a version which stores the height (of the previous column) and calls \my@calcextraspace
\gdef\column#1{ % #1: relative width
\ifTP@columnEnvironment
\my@storecolheight
\stepcounter{my@column}
\my@calcextraspace
\setcounter{my@block}{0}
\my@blocktopstart0pt
\my@colheight0pt
% Now the normal \column command
\normalsize
\setlength{\TP@blocktop}{\TP@coltop}
\setlength{\TP@colcenter}{\TP@colcenter+0.5\colwidth+\TP@colspace}
\setlength{\colwidth}{#1\TP@visibletextwidth+#1\TP@colspace-\TP@colspace-\blocklinewidth}
\setlength{\TP@colcenter}{\TP@colcenter+0.5\colwidth+\blocklinewidth}
\fi
}
% Replace the columns environment with a version which stores the height of the final column and the max column
\renewenvironment{columns}{
\TP@columnEnvironmenttrue
\setlength{\TP@colcenter}{-0.5\TP@visibletextwidth-\TP@colspace-0.5\blocklinewidth}
\global\TP@colcenter=\TP@colcenter
\global\TP@coltop=\TP@blocktop
\global\TP@colbottom=\TP@blocktop
\colwidth=0pt
}{
\my@storecolheight
\my@storemaxcolheight
\TP@columnEnvironmentfalse
\global\TP@blocktop=\TP@colbottom
}
\fi
The problem is that tikzposter
puts the title inside a \scalebox
thus preventing line breaks. You can recover line breaking placing your title inside a \parbox
:
\documentclass{tikzposter}
\title{\parbox{\linewidth}{\centering This is a really really really really really really really really really long title for a poster}}
\institute{The Institute}
\author{The Author}
\titlegraphic{Logo}
\usetheme{Basic}
\begin{document}
\maketitle
\block{BlocktitleA}{Blocktext}
\begin{columns}
\column{0.3}
\block{BlocktitleB}{Blocktext}
\column{0.7}
\block{BlocktitleC}{Blocktext}
\note{Notetext}
\end{columns}
\end{document}
Related Question
- [Tex/LaTex] Columns environment doesn’t scale to full paper size tikzposter (using custom paper size)
- [Tex/LaTex] Blocks overflow the poster using tikzposter
- [Tex/LaTex] Text alignment within tikzfigure environment of the tikzposter class
- [Tex/LaTex] Setting the height or position of a block in tikzposter
- [Tex/LaTex] Change vertical spacing between blocks in tikzposter
Best Answer
basically you don't like line 426 which says
If it said
then you would get justified text (and fix the
\par
issue of your other question. It's a bit inconvenient to patch that you could just edit a local, renamed, copy and use that instead, or simpler just putat the start of your block entry, and
at the end. (The need for
\par
is a bug in the class file really, so you could report that)If you do want to patch it, egreg suggests:
which would save editing a local copy of the class.