GeneralHow to center a title in a mdframed box?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to center a title in a mdframed box?

Post by Cham »

I'm having a problem in centering a title inside this simple mdframed code :

Code: Select all

\RequirePackage[l2tabu,orthodox]{nag}
\documentclass[12pt,letterpaper]{article}
\usepackage{xcolor}
\usepackage{mdframed}
\mdfsetup{}

\begin{document}

Blablabla

\begin{mdframed}[
	frametitle={Some funky title},
	frametitlealignment=center, % <--- what's wrong here ?  \center doesn't fix this.
	frametitlefont=\sffamily,
	frametitlerule=true,
	frametitlebackgroundcolor=gray!20,
	linecolor=black,
	backgroundcolor=white,
	linewidth=0.5pt,
	leftmargin=0cm,
	rightmargin=0cm,
	topline=true,
	bottomline=true,
	innertopmargin=1ex,
	shadow=true,
	shadowsize=1.5pt,
	shadowcolor=gray!30
]

Some braindead blabla in a cool box.

\end{mdframed}

\end{document}
The mdframed package documentation doesn't give the options to be used for the frametitlealignment command, except default=\raggedleft.

nag gives an error message about the centering command.

What should be the proper solution to center the title ?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to center a title in a mdframed box?

Post by Johannes_B »

Why not using tcolorbox?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to center a title in a mdframed box?

Post by Cham »

You mean replacing mdframed with tcolorbox ? mdframed is working very well, there's just this title centering which causes a nag problem. Is this a bug ?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to center a title in a mdframed box?

Post by Johannes_B »

No idea, probably not a big.
I'll have a look later.

tcolorbox is more powerful these days.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to center a title in a mdframed box?

Post by Cham »

Doh! :lol:

Apparently, the proper option to center the title in mdframed isn't center, or \center, it's \centering!

Code: Select all

frametitlealignment=\centering,
No more nag warnings.

Why haven't I tried this before? And why it isn't shown in the documentation? Such is LaTeX, I guess. :roll:

The issue appears to be solved.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to center a title in a mdframed box?

Post by Johannes_B »

\center is never correct use. center is an environment.

We had this before.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to center a title in a mdframed box?

Post by Cham »

Yes, but we're talking about a package with options. Most of the options are simple words, not commands, like this :

Code: Select all

\begin{mdframed}[
	frametitle={Put a title in there},
	frametitlerule=true,
	linecolor=black,
	backgroundcolor=white,
	...
]

Blabla

\end{mdframed}
So for the frametitlealignment option, I was expecting a simple word like "center" or "centered", not a command.
But it's working great anyway. The issue is solved.
Post Reply