Page LayoutChange the Text of a tikZ Picture in Header

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
amdx64bt
Posts: 5
Joined: Mon Feb 08, 2010 2:10 am

Change the Text of a tikZ Picture in Header

Post by amdx64bt »

I have this header:

Code: Select all

\ihead{\hspace{-2mm}
\begin{tikzpicture}[remember picture,overlay]
  \node [xshift=\paperwidth/2,yshift=-\headheight] (mybar) at (current page.north west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=4\headheight,top color=mybgcolor!64,bottom color=mybgcolor]{};
\end{tikzpicture}
\chapter
}
And I would like to use the same header and to change the Title of the chapter of this header using only a line of code, something like this:

Code: Select all

\chapterheader{New Title of pages 1-4}
How I can get this?
Last edited by localghost on Wed Feb 15, 2012 9:34 pm, edited 1 time in total.

Recommended reading 2024:

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

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 10322
Joined: Mon Mar 10, 2008 9:44 pm

Change the Text of a tikZ Picture in Header

Post by Stefan Kottwitz »

Hi,

is this all what you have?
\ihead is defined by fancyhdr and by scrpage2. Which one do you use? Which document class? It would be better if you would post a more complete example. The best would be a compilable example of what you tried.

Here it's also unclear what you mean by \chapter without an argument, the title. And to where the brace in the last line belongs to.

Stefan
LaTeX.org admin
amdx64bt
Posts: 5
Joined: Mon Feb 08, 2010 2:10 am

Re: Change the Text of a tikZ Picture in Header

Post by amdx64bt »

I use the scrpage2.

The source code of the example that I use is here:
http://tug.org/pracjourn/2010-2/hofert.html
User avatar
Stefan Kottwitz
Site Admin
Posts: 10322
Joined: Mon Mar 10, 2008 9:44 pm

Re: Change the Text of a tikZ Picture in Header

Post by Stefan Kottwitz »

Just an advice, I guess there's a better chance that users would help if you would give your example with which you work, a small version. I doubt that many user would analyze a complete journal article source code with template and class. Do you really use the pracjourn class for your document?

If I would have a problem, I would create a small compilable example which shows it, and post that here, instead of just telling somewhere else it would be a part of.

Stefan
LaTeX.org admin
amdx64bt
Posts: 5
Joined: Mon Feb 08, 2010 2:10 am

Change the Text of a tikZ Picture in Header

Post by amdx64bt »

Here is the code of an smaller example:

Code: Select all

\documentclass[
  paper=128mm:96mm,% like beamer
  fontsize=11pt,% like beamer
  pagesize,% write page size to dvi or pdf
  parskip=half-,% paragraphs are separated by half a line, no special marking of line endings
  numbers=noendperiod,% removes points for special parts (e.g. appendix)
  captions=nooneline% do not distinguish between one or more lines in captions
]{scrartcl}
\linespread{1.12}% enlarge line space

\newcommand*{\mytitle}{Title First Page}
\newcommand*{\myhead}{\mytitle}

% font stuff
\usepackage[T1]{fontenc}% for correct hyphenation and T1 encoding
\AfterFile{t1lmss.fd}{% see http://www.komascript.de/node/823
  \DeclareFontShape{T1}{lmss}{b}{n}
  {<->ssub*lmss/bx/n}{}
}
\usepackage{lmodern}% latin modern font
\usepackage{charter}% low-resolution roman font
\usepackage[american]{babel}% for American English
\usepackage{microtype}% for character protrusion and font expansion (only with pdflatex)

% page structure
\usepackage{calc}% working with lengths, counters etc.
\usepackage[includeheadfoot,top=3.5mm,bottom=3.5mm,left=5.5mm,right=5.5mm,headsep=6.5mm,footskip=8.5mm]{geometry}% set page layout parameters
\usepackage{scrpage2}% package for page style with not only uppercase letters in the head
\usepackage{titlesec}% for reducing space between ((sub)sub)sections and text
\usepackage{tocstyle}% for adjusting table of contents

% misc
\usepackage{amsthm}% theorem environments
\usepackage{bm}%for bold math symbols
\usepackage{enumitem}% for automatic numbering of new enumerate environments
\usepackage{graphicx}% for including figures
\usepackage{tikz}% sophisticated graphics package
\usepackage{tabularx}% for special table environment (tabularx-table)
\usepackage{booktabs}% for table layout
\usepackage[style=authoryear]{biblatex}% for bibliography
\usepackage[
  hypertexnames=false,% for correct links (duplicate-error solution)
  setpagesize=false,% necessary in order to not change text-/paperformat for the document
  pdfborder={0 0 0},% removes border around links
  pdfstartview=Fit% fit page to pdf viewer
]{hyperref}% all links stay black and are thus invisible


% page style
\pagestyle{scrheadings}% activates pagestyle from scrpage2
\clearscrheadfoot% clear head and foot of scrheadings and scrplain
\setkomafont{pageheadfoot}{\normalfont\color{white}\sffamily}% setting for page head and foot

% head (optional argument is scrplain, mandatory scrheadings)
\ihead{% head left
  \hspace{-2mm}%
  \begin{tikzpicture}[remember picture,overlay]
    \node [xshift=\paperwidth/2,yshift=-\headheight] (mybar) at (current page.north west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=2\headheight,top color=mybgcolor!64,bottom color=mybgcolor]{};
  \end{tikzpicture}%
\chapter{Title First Page}
}

  \begin{document}
  First Page.
  \clearpage

  In this frame I would like to change the Title of the header Title First Page by Title Second Page.
  \clearpage
  \end{document}
Last edited by Stefan Kottwitz on Wed Feb 15, 2012 11:34 pm, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10322
Joined: Mon Mar 10, 2008 9:44 pm

Change the Text of a tikZ Picture in Header

Post by Stefan Kottwitz »

This example is also very big. Generally, try to reduce as much as possible, removing everything what is not relevant for the problem. So people could more easily help. Here, for example, many packages such as amsthm, bm, enumitem, biblatex etc. are not relevant. Does a tester has to install biblatex? This code is not compilable. mybgcolor is undefined and leads to a compiler error - readers have to debug it before they can even test your actual problem. Chapters are not supported by scrartcl, but by scrbook and scrreprt.

Perhaps you don't have much experience in LaTeX or in a forum like this. I just explain to tell you what's the best way to get help. In most cases, a good example to a problem leads to a quick and clear solution. Very helpful in this regard:
Here are compilable example documents which do what you desire: Fancy chapter headings with TikZ. In the comments to this post there's an example for scrartcl together with scrpage2.

Stefan
LaTeX.org admin
Banny
Posts: 5
Joined: Mon Apr 30, 2012 7:12 pm

Change the Text of a tikZ Picture in Header

Post by Banny »

Hi Stephan

The "Fancy chapter headings with TikZ" created by you is amazing i am thinking of using it in my work. Can I just ask one question? I was studying the titlesec documentation to understand this part of code:

Code: Select all

\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
?  {\gdef\chapterlabel{\thechapter\ }}{0pt}
!  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle
          (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue]
              {\color{white}\chapterlabel#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
In general i know how it works but i don't know where belong the lines, marked by me with "?" and "!" in the code above, to this structure of titleformat command :
\titleformat{command}[shape]{format}{label}{sep}{before-code}[after-code]
I hole that you understand what do i mean. Thank you

Banny
Post Reply