2

I would like to automatically center a sentence within a Bclogo box; that is, I would like to place the sentence such that its center lies (technically) at the midpoint of the diagonal endpoints of the rectangular-shaped bclogo.

Based on how one might automatically center a divider in the TOC, I tried the following code:

\documentclass{book}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usetikzlibrary{calc,shapes.callouts,shapes.arrows}

\begin{document}
\thispagestyle{empty}
\Huge
\begin{center} 
\begin{bclogo}[couleur=red!10,  %couleur=blue!14, %couleur=blue!20, 
epBord=3.5, arrondi=0, %logo=\bcplume, %\bclampe,marge=8, 
logo= ,
%ombre=true, blur, couleurBord=blue!14, %couleurBord=blue!60,
barre=none, %barre=snake, tailleOndu=1.5
]{\hfil{This sentence is not centered.}\hfil}
\end{bclogo}
\end{center}
\end{document}

which produces

enter image description here

I have noticed, surprisingly to me, that if I replace \hfil by \hfill I get the following:

enter image description here

which looks pretty much like a goof horizontal centering, but clearly, not vertically centered.

In the past, I have spent a considerable amount of time trying to center a sentence by many manual trial-and-error adjustments; and so, I would like to pose the following question.

QUESTION: How may I center a sentence in the described Bclogo such that it is automatically both vertically and horizontally centered? Also, does anyone know why \hfil does not do the job as it seems to when I have used it to center an item in a TOC: and also, why is the vertical centering so egregiously off when I use \hfill?

Thank you.

4
  • 1
    Wouldn't it be simpler to make this with \colorbox?
    – Bernard
    Aug 21, 2021 at 21:35
  • the content is a parbox with parfillskip \hfil so you could centre with \cemtering but if you put hfill both sides it centres, if you put hfil both sides you have 1hfil on the right because of the parfillskip. But theer is some additional fixed space on the right even if you use \centering, not sure where that comes from yet Aug 21, 2021 at 21:38
  • note the first argument that you are using is the title of the box {you currently have no content) so vertically centering it would be a bit of a mis-use. Aug 21, 2021 at 21:40
  • @Bernard Yes; but in the past I recall also having run into this kind of a problem with Bclogos of different shapes. Since I had this Bclogo handy (and also, it is easier to describe what I am looking for if a rectangular shape is used), I posted the question in with the hope that a general solution might be had. Aug 21, 2021 at 22:46

1 Answer 1

3

The mandatory argument to bclogo is the title. You want

\begin{bclogo}[<options>]{}
  text for the box
\end{bclogo}

but you first need to remove the space reserved for the title, that's inserted no matter what.

\documentclass{book}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usetikzlibrary{calc,shapes.callouts,shapes.arrows}

\pagestyle{empty}

\begin{document}

\begin{bclogo}[
  couleur=red!10,
  %couleur=blue!14,
  %couleur=blue!20,
  epBord=1.5,
  arrondi=0,
  logo=,
  %logo=\bcplume,
  %logo=\bclampe,
  %marge=8, 
  %ombre=true,
  %blur,
  %couleurBord=blue!14,
  %couleurBord=blue!60,
  barre=none,
  %barre=snake,
  %tailleOndu=1.5
]{}
\vspace*{-\ht\strutbox}
\vspace*{-\dp\strutbox}

\vspace{1cm}

\centering This sentence is centered.

\vspace{1cm}

\end{bclogo}

\end{document}

enter image description here

Without the two \vspace{1cm} instructions you'd get

enter image description here

1
  • Thank you kindly for this very informative answer. I was not aware of -\ht\strutbox and -\dp\strutbox prior to this. Aug 22, 2021 at 16:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .