6

I need to change the aspect of the chapter's title. I tryed tikz, using this other thread: Is there is a package so you can add text with visual effects like "WordArt" from "Word"

This is my code:

\documentclass[twoside,fleqn]{book}
\usepackage[utf8]{inputenc}   
\usepackage{lipsum} 
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{fadings,decorations.text}
\titleformat{\chapter}[display]
{\flushleft\normalfont}
{} {20pt}
{%
\begin{tikzfadingfrompicture}[name=tikz]
 \node at (-14,-3) [text=transparent!20]
 {\fontfamily{ptm}\Huge\selectfont\textbf{\textsc{#1}}  };
 \end{tikzfadingfrompicture}
\begin{tikzpicture}
\shade[path fading=tikz,fit fading=false,
left color=red,right color=orange]
 (-7,-1) rectangle (8,1);
\end{tikzpicture}
          }
\begin{document}
\chapter{Not so long title}
\lipsum[1-2]

\chapter{Very very very very loooong title-Centered}
\lipsum[1-2]
\end{document}

But it's not aligned with the text, it's centered instead. How can I align it to the left? Can I also put the tikz title into a tcolorbox? I wanted a frame and the number..

Francesco
  • 361
  • I am not sure what you want to achieve actually, but perhaps this is similar: http://tex.stackexchange.com/questions/248123/how-to-create-partial-borders-around-section-titles. You can use tikz code in the overlay feature of tcolorbox –  Dec 14 '15 at 19:11
  • Do you want it centred relative to the width of the text block rather than the page width? – cfr Dec 14 '15 at 23:14
  • I played with your code but I can't figure out what you want it to do. – cfr Dec 14 '15 at 23:21
  • No, I want the title on the left, such that the abscissa where the normal text and the title starts would be the same for both. – Francesco Dec 15 '15 at 10:25
  • @ChristianHupfer yes, I'll try (not sure of results). Thank you! – Francesco Dec 15 '15 at 10:30
  • I tried, but with no results..! I mean, the are no errors, but it's still centered. There's a way I can use x/yshift? I can't move the title.. – Francesco Dec 15 '15 at 17:15

1 Answers1

2

The chapter titles are actually aligned left --- the left side of the rectangle (-7,-1) rectangle (8,1) touches the left border of the text area. To see this, one may delete path fading=tikz to get

So the solution is to make a rectangle that fits the title. Perhaps the best way is to do everything again, transparently.

\titleformat{\chapter}[display]{\flushleft\normalfont}{}{20pt}
{
    \begin{tikzfadingfrompicture}[name=tikz]
        \node[text width=20cm,text=transparent!20]
        {\fontfamily{ptm}\Huge\selectfont\textbf{\textsc{#1}}\\};
    \end{tikzfadingfrompicture}
    \begin{tikzpicture}
        \node[text width=20cm,text opacity=0,shade,path fading=tikz,fit fading=false,left color=red,right color=orange]
        {\fontfamily{ptm}\Huge\selectfont\textbf{\textsc{#1}}\\};
    \end{tikzpicture}
}

So one has

and

Symbol 1
  • 36,855
  • I think I can fix the problem with tcolorbox, and insert the number, so that's what I was looking for. Thanks a lot!! – Francesco Dec 17 '15 at 21:15