Archive for the ‘LaTeX’ Category.

Pocketmod – TODO Listen in A3

Zum Thema Pocketmod hatte ich schon früher etwas geschrieben (https://www.uweziegenhagen.de/?p=1294), hier nun ein Template für ein TODO-Listen Pocket in DIN A3.

Das fertige PDF sieht dann so aus: PocketMod_for_A3

\documentclass[21pt]{scrartcl}
\usepackage[left=2cm,right=2cm, top=2cm,bottom=2cm,a3paper]{geometry}
 
\usepackage{forloop}
\setlength{\parindent}{0pt}
\usepackage{tikz}
 
\newcounter{ct} 
\usepackage{pgfpages}
 
\def\pgfpageoptionheight{\the\paperwidth} % landscaped by default
\def\pgfpageoptionwidth{\the\paperheight}
\def\pgfpageoptionborder{0pt}
\def\pgfpageoptionfirstshipout{1}
 
\pgfpagesphysicalpageoptions{%
    logical pages=8,%
    physical height=\pgfpageoptionheight,%
    physical width=\pgfpageoptionwidth,%
    current logical shipout=\pgfpageoptionfirstshipout%
}
 
    \pgfpageslogicalpageoptions{1}{%
      border shrink=\pgfpageoptionborder,%
      resized width=.25\pgfphysicalwidth,%
      border code=\pgfusepath{stroke},%
      resized height=0.5\pgfphysicalheight,%
      center=\pgfpoint{.875\pgfphysicalwidth}{.75\pgfphysicalheight}%
    }%
    \pgfpageslogicalpageoptions{2}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.25\pgfphysicalwidth,%
      border code=\pgfusepath{stroke},%
      rotation=180,%      
      resized height=0.5\pgfphysicalheight,%
      center=\pgfpoint{.875\pgfphysicalwidth}{.25\pgfphysicalheight}%
    }%
 
    \pgfpageslogicalpageoptions{3}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.25\pgfphysicalwidth,%
      border code=\pgfusepath{stroke},%
      rotation=180,%      
      resized height=0.5\pgfphysicalheight,%
      center=\pgfpoint{.625\pgfphysicalwidth}{.25\pgfphysicalheight}%
    }%
    \pgfpageslogicalpageoptions{4}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.25\pgfphysicalwidth,%
      border code=\pgfusepath{stroke},%
      rotation=180,%      
      resized height=0.5\pgfphysicalheight,%
      center=\pgfpoint{.375\pgfphysicalwidth}{.25\pgfphysicalheight}%
    }%
 
    \pgfpageslogicalpageoptions{5}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.25\pgfphysicalwidth,%
      border code=\pgfusepath{stroke},%
      rotation=180,%
      resized height=0.5\pgfphysicalheight,%
      center=\pgfpoint{.125\pgfphysicalwidth}{.25\pgfphysicalheight}%
    }%
    \pgfpageslogicalpageoptions{6}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.25\pgfphysicalwidth,%
      border code=\pgfusepath{stroke},%
      resized height=0.5\pgfphysicalheight,%
      center=\pgfpoint{.125\pgfphysicalwidth}{.75\pgfphysicalheight}%
    }%
 
    \pgfpageslogicalpageoptions{7}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.25\pgfphysicalwidth,%
      border code=\pgfusepath{stroke},%
      resized height=0.5\pgfphysicalheight,%
      center=\pgfpoint{.375\pgfphysicalwidth}{.75\pgfphysicalheight}%
    }%
    \pgfpageslogicalpageoptions{8}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.25\pgfphysicalwidth,%
      border code=\pgfusepath{stroke},%
      resized height=0.5\pgfphysicalheight,%
      center=\pgfpoint{.625\pgfphysicalwidth}{.75\pgfphysicalheight}%
    }%
 
 
\begin{document}%
 
\forloop{ct}{1}{\value{ct} < 9}{%
\begin{tikzpicture}
\foreach \i in {0,...,-17}{%
\draw[very thick] (0,\i*2) -- ++(0,1.5) -- ++(1.5,0) -- ++(0,-1.5)--cycle; 
\draw[very thick] (2.5,\i*2) -- (22,\i*2);
\draw[very thick] (23,\i*2) -- ++(0,1.5) -- ++(1.5,0) -- ++(0,-1.5)--cycle; 
}
\end{tikzpicture}
\clearpage
}
 
\end{document}

Gittermuster erstellen mit gridpapers

Hier ein Beispiel dafür, wie man mit dem gridpapers Paket Muster auf Papier bringen kann, hier ein Punktmuster.

%!TEX TS-program = Arara
% arara: pdflatex: {shell: yes}
\documentclass[12pt,ngerman]{scrartcl}
\areaset{8cm}{16cm}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\pagestyle{empty}
\usepackage[pattern=dot,% 
colorset=std,
geometry={left=2.25cm,right=1.25cm,top=1cm,bottom=1.25cm},%
textarea,%
patternsize={5mm},%
dotsize={1pt}
]{gridpapers}
 
\begin{document}
~
 
\end{document}

Auszug aus der A4-Seite:

Dymo Labels mit LaTeX und ticket.sty gestalten

Hier ein kurzes Beispiel, wie man mit LaTeX auch Dymo-Labels erzeugen kann, im Beispiel für die Label-Größe 57*32mm. Zum allgemeinen Verständnis von ticket.sty siehe auch meinen DTK Artikel in Ausgabe 1/2021.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[landscape,paperheight=57mm,paperwidth=32mm,left=0mm,top=0mm,right=0mm,bottom=0mm]{geometry}
%\usepackage[sfdefault]{plex-sans}
\usepackage{palatino}
 
\begin{filecontents}[overwrite]{Dymo5732.tdf}
\unitlength=1mm
\hoffset=-25.4mm
\voffset=-29mm
\ticketNumbers{1}{1}
\ticketSize{57}{32} % Breite und Hoehe der Labels in mm
\ticketDistance{0}{0} % Abstand der Labels
\end{filecontents}
 
\usepackage[Dymo5732]{ticket}
 
\renewcommand{\ticketdefault}{}%
\makeatletter
\@boxedfalse % Rahmen um Ticket
\@emptycrossmarkfalse % Falzmarken
\@cutmarkfalse % Schnittmarken
\makeatother
 
\newcommand{\myticket}[2]{
\ticket{%
\put(10,10){\scalebox{#1}{\bfseries #2}}
}}
 
\newcommand{\myticketml}[4]{
\ticket{%
\put(5,20){\scalebox{#1}{\bfseries #2}}
\put(5,15){\scalebox{#1}{\bfseries #3}}
\put(5,10){\scalebox{#1}{\bfseries #4}}
}}
 
 
\begin{document}
\myticketml{1.25}{Dr. Max  Mustermann}{Musterweg 123}{54321~Musterstadt}
\myticket{2}{Steuern}
\end{document}

PDF

Nützliche Kommandozeilen-Einzeiler für LaTeX

Unter https://gist.github.com/iwishiwasaneagle/2f91f63f3cb0107b94b501aa284a18ca gibt es eine Sammlung an nützlichen Einzeilern für die Arbeit mit LaTeX.

Aktienkurse mit Python und LaTeX auswerten

Hier ein einfaches Beispiel, wie man mit Python und LaTeX ein PDF mit Kursinformationen erstellen kann.

Zuerst der Python-Teil, der die Apple-Kursdaten seit dem 1.1.2021 in einen Dataframe lädt und dann in eine LaTeX-Tabelle schreibt:

import pandas
import pandas_datareader.data as web
 
YAHOO_TODAY="http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=sd1ohgl1vl1"
 
history = web.DataReader('AAPL', "yahoo", start="2021-1-1")
history.to_latex('aapl.tex')

Dann noch der LaTeX-Teil, der a) den Python-Code aus dem LaTeX-Lauf heraus ausführt und b) die erzeugte Tabellen-Datei nur dann einbindet, wenn sie wirklich auch erzeugt wurde.

\documentclass[12pt,ngerman]{scrartcl}
\usepackage[a4paper, top=1cm,bottom=1cm,left=1cm, right=1cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
 
\makeatletter
\newcommand{\testfileexists}[1]{%
  \IfFileExists{#1}%
    {\def\inputtestedfile{\@@input #1 }}
    {\let\inputtestedfile\@empty}%
}
\makeatother
 
\begin{document}
 
\write18{python runpy.py}
 
  \testfileexists{aapl}
      \inputtestedfile
 
 
\end{document}

Update vom 05.05.2024:

Um den DataFrame zu befüllen, funktioniert der obige Code nicht mehr. Hier ist ein Workaround zum Anpassen:

import pandas as pd
import yfinance as yf
df = pd.DataFrame(yf.download('MSFT', start = '2012-01-01', end='2017-01-01'))

Farbige Boxen in LaTeX mit tcolorbox

Hier einige Beispiele für farbige Boxen mit dem tcolorbox Paket, entnommen der Paketbeschreibung

\documentclass[12pt,ngerman]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{csquotes}
\usepackage{paralist}
\usepackage{xcolor}
\usepackage{blindtext}
\usepackage{microtype}
 
\usepackage{empheq}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
 
\newtcbtheorem[number within=section]{mytheo}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}
 
\begin{document}
 
 
\begin{tcolorbox}
Hallo Welt!
\end{tcolorbox}
 
 
\begin{tcolorbox}
\blindtext
\end{tcolorbox}
 
\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black,title=My nice heading]
This is another \textbf{tcolorbox}.
\tcblower
Here, you see the lower part of the box.
\end{tcolorbox}
 
\begin{mytheo}{This is my title}{theoexample}
This is the text of the theorem. The counter is automatically assigned and,
in this example, prefixed with the section number. This theorem is numbered with
\ref{th:theoexample}, it is given on page~\pageref{th:theoexample}.
\end{mytheo}
 
 
\begin{equation}
\tcbset{fonttitle=\footnotesize}
\tcboxmath[colback=yellow!25!white,colframe=blue]{ a^2 = 16 }
\quad \Rightarrow \quad
\tcboxmath[colback=blue!25!white,colframe=red,title=Implication]%
{ a = 4 ~\vee~ a=-4. }
\end{equation}
 
 
\newtcbox{\otherbox}[1][]{nobeforeafter,math upper,tcbox raise base,
enhanced,frame hidden,boxrule=0pt,interior style={top color=green!10!white,
bottom color=green!10!white,middle color=green!50!yellow},
fuzzy halo=1pt with green,#1}
\begin{empheq}[box=\otherbox]{align}
a&=\sin(z)\\
E&=mc^2 + \int_a^b x\, dx
\end{empheq}
\begin{equation}
\tcbhighmath{E} = \otherbox{mc^2}
\end{equation}
 
 
\newtcolorbox{mybox}[2][]{colback=red!5!white,
colframe=red!75!black,fonttitle=\bfseries,
colbacktitle=red!85!black,enhanced,
attach boxed title to top center={yshift=-2mm},
title=#2,#1}
\begin{mybox}[colback=yellow]{Hello there}
This is my own box with a mandatory title
and options.
\end{mybox}
 
\begin{tcolorbox}[enhanced,
size=minimal,auto outer arc,
width=2.1cm,octogon arc,
colback=red,colframe=white,colupper=white,
fontupper=\fontsize{6mm}{6mm}\selectfont\bfseries\sffamily,
halign=center,valign=center,
square,arc is angular,
borderline={0.2mm}{-1mm}{red} ]
STOP
\end{tcolorbox}
 
\begin{tcolorbox}[enhanced,
size=minimal,auto outer arc,
width=2.1cm,octogon arc,
colback=green,colframe=white,colupper=black,
fontupper=\fontsize{6mm}{6mm}\selectfont\bfseries\sffamily,
halign=center,valign=center,
square,arc is angular,
borderline={0.2mm}{-1mm}{green}]
GO
\end{tcolorbox}
\end{document}

Kurszertifikate mit LaTeX erstellen

Das pgfornaments Paket erlaubt es, spezielle Schmuckzeichen für beispielsweise Kurszertifikate zu nutzen. Hier ein Beispiel, das ich gern für die Teilnehmerinnen und Teilnehmer meiner LaTeX-Kurse nutze.

\documentclass[16pt,ngerman]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{eso-pic,calc} 
\usepackage{babel}
\usepackage{graphicx}
\usepackage{csquotes}
\usepackage{paralist}
\usepackage{xcolor}  
\usepackage[a4paper,landscape,bottom=1.5cm]{geometry} % left=0pt,right=0pt,top=0pt,bottom=0pt
\usepackage{palatino,dashrule}
\usepackage{pgfornament}
\pagestyle{empty}
 
\setlength{\parindent}{0pt}
 
\makeatletter
\AddToShipoutPicture{%
  \begingroup 
    \setlength{\@tempdima}{5mm}%
    \setlength{\@tempdimb}{\paperwidth-\@tempdima-3cm}%
    \setlength{\@tempdimc}{\paperheight-\@tempdima}%
    \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimc}){%
            \pgfornament[color=magenta,anchor=north west,width=3cm]{63}} 
    \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdima}){%
            \pgfornament[color=magenta,anchor=south west,width=3cm,symmetry=h]{63}}
    \put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdima+\paperheight-1cm}){%
            \pgfornament[color=magenta,anchor=north east,width=3cm,symmetry=v]{63}}    
    \put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdima+\paperheight-21cm}){%
            \pgfornament[color=magenta,anchor=south east,width=3cm,symmetry=c]{63}} 
  \endgroup  
} 
\let\strippt\strip@pt     
\makeatother   
 
 
\begin{document}
 
\centering\Huge
 
\textbf{Zertifikat}
\vspace{20mm}
\begin{center}
Max Mustermann%\hdashrule[0.75ex]{14cm}{1pt}{3mm}
\end{center}
\vspace{1cm}\huge
 
hat erfolgreich am zweitägigen \LaTeX-Kurs der Musteruni teilgenommen. \vspace{2cm}\LARGE\flushleft
 
Musterau, \hfill\hdashrule[0.75ex]{9.5cm}{1pt}{2mm}
 
\today
 
\begin{center}
\vfill\pgfornament[width=0.7\textwidth]{88}
\end{center}
\end{document}

Schöne Matrizen mit nicematrix

Um ansprechende Matrizen zu setzen gibt es mit dem nicematrix Paket ein recht neues Paket, das sich alle anschauen sollten, die viel mit Matrizen zu tun haben. Die folgenden Beispiele sind der Dokumentation entnommen, teilweise braucht man mehrere LaTeX-Läufe für das finale Ergebnis.

%!TEX TS-program = Arara
% arara: pdflatex: {shell: yes}
\documentclass[12pt,ngerman]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{xcolor} 
 
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-top-limit = 1pt,cell-space-bottom-limit = 1pt}
\begin{document}
 
\begin{equation}
\begin{pmatrix}
\frac12 & -\frac12 \\
\frac13 & \frac14 \\
\end{pmatrix}
=
\begin{pNiceMatrix}
\frac12 & -\frac12 \\
\frac13 & \frac14 \\
\end{pNiceMatrix}
\end{equation}
 
\begin{equation}
A = \begin{pNiceMatrix}[baseline=2]
\frac{1}{\sqrt{1+p^2}} & p & 1-p \\
1 & 1 & 1 \\
1 & p & 1+p
\end{pNiceMatrix}
\end{equation}
 
 
\NiceMatrixOptions{cell-space-top-limit=1pt,cell-space-bottom-limit=1pt}
 
\begin{equation}
A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
\dfrac1A & \dfrac1B & 0 & 0 \\
\dfrac1C & \dfrac1D & 0 & 0 \\
\hline
0 & 0 & A & B \\
0 & 0 & D & D \\
\end{pNiceArray}
\end{equation}
 
 
\begin{equation}
\begin{NiceArray}{*{5}{c}}[hvlines]
\diagbox{x}{y} & e & a & b & c \\
e & e & a & b & c \\
a & a & e & c & b \\
b & b & c & e & a \\
c & c & b & a & e
\end{NiceArray}
\end{equation}
 
 
\NiceMatrixOptions{code-for-first-row = \color{red},
code-for-first-col = \color{blue},
code-for-last-row = \color{green},
code-for-last-col = \color{magenta}}
 
\begin{equation}
\begin{pNiceArray}{cc|cc}[first-row,last-row=5,first-col,last-col,nullify-dots]
& C_1 & \Cdots & & C_4 & \\
L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\
\Vdots & a_{21} & a_{22} & a_{23} & a_{24} & \Vdots \\
\hline
& a_{31} & a_{32} & a_{33} & a_{34} & \\
L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\
& C_1 & \Cdots & & C_4 &
\end{pNiceArray}
\end{equation}
 
\begin{equation}
\begin{pNiceArray}{ScWc{1cm}c}[nullify-dots,first-row]
{C_1} & \Cdots & & C_n \\
2.3 & 0 & \Cdots & 0 \\
12.4 & \Vdots & & \Vdots \\
1.45 \\
7.2 & 0 & \Cdots & 0
\end{pNiceArray}
\end{equation}
 
\[\begin{NiceMatrix}[
code-before =
{
\tikz \draw [fill = red!15]
(row-7-|col-4) -- (row-8-|col-4) -- (row-8-|col-5) --
(row-9-|col-5) -- (row-9-|col-6) |- cycle ;
}
]1
\\
1 & 1 \\
1 & 2 & 1 \\
1 & 3 & 3 & 1 \\
1 & 4 & 6 & 4 & 1 \\
1 & 5 & 10 & 10 & 5 & 1 \\
1 & 6 & 15 & 20 & 15 & 6 & 1 \\
1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 \\
1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1
\end{NiceMatrix}\]
 
 
\(
\begin{bNiceMatrix}
C[a_1,a_1] & \Cdots & C[a_1,a_n]
& \hspace*{20mm} & C[a_1,a_1^{(p)}] & \Cdots & C[a_1,a_n^{(p)}] \\
\Vdots & \Ddots & \Vdots
& \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
C[a_n,a_1] & \Cdots & C[a_n,a_n]
& & C[a_n,a_1^{(p)}] & \Cdots & C[a_n,a_n^{(p)}] \\
\rule{0pt}{15mm} & \Vdotsfor{1} & & \Ddots & & \Vdotsfor{1} \\
C[a_1^{(p)},a_1] & \Cdots & C[a_1^{(p)},a_n]
& & C[a_1^{(p)},a_1^{(p)}] & \Cdots & C[a_1^{(p)},a_n^{(p)}] \\
\Vdots & \Ddots & \Vdots
& \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
C[a_n^{(p)},a_1] & \Cdots & C[a_n^{(p)},a_n]
& & C[a_n^{(p)},a_1^{(p)}] & \Cdots & C[a_n^{(p)},a_n^{(p)}]
\end{bNiceMatrix}
\)
 
\end{document}

Das subcaption Paket als subfigure Ersatz

Um mehreren nebeneinander gesetzten Bildern separate Bildunterschriften zu geben, war das subfigure Paket lange Standard. Mit dem subcaption Paket von Axel Sommerfeldt gibt es einen würdigen Nachfolger, der aktiv gepflegt wird.

Hier ein Beispiel, zum Übersetzen bitte eigene Bilder nutzen:

\documentclass[12pt,ngerman]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{subcaption}
 
\begin{document}
 
\begin{figure}
\centering
\subcaptionbox{Eine Katze \label{cat1}}
{\includegraphics[width=0.49\textwidth]{Bilder/Katze1}}
\subcaptionbox{Die selbe Katze \label{cat2}}
{\includegraphics[width=0.49\textwidth]{Bilder/Katze2}}
\caption{Zwei Katzenbilder}\label{katzenbilder}
\end{figure}
 
Abbildung \ref{cat1} auf Seite \pageref{katzenbilder}
 
Abbildung \ref{cat2} auf Seite \pageref{katzenbilder}
 
Abbildung \ref{katzenbilder} auf Seite \pageref{katzenbilder}
 
\end{document}

Flyer mit LaTeX gestalten

Um einen einfachen Flyer zu erstellen gibt es nichts besseres als die leaflet-Klasse. Hier ein einfaches Beispiel, die Katzenbilder muss man zum Übersetzen auskommentieren oder ersetzen.

\documentclass[12pt,ngerman]{leaflet}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{csquotes}
\usepackage{paralist}
\usepackage{xcolor}
\usepackage{palatino}
\usepackage{blindtext}
\usepackage{microtype}
 
\author{Uwe Ziegenhagen}
\title{Mein erster Flyer}
 
\begin{document}
\maketitle
\thispagestyle{empty}
 
\section{Foo}
 
\blindtext[2]
 
\section{Bar}
 
\includegraphics[width=\textwidth]{Bilder/Katze2}
 
\blindtext
 
\section{Hello}
 
\blindtext[4]
 
\section{World}
 
\blindtext
 
\section{Hallo Welt}
 
\blindtext
 
\includegraphics[width=\textwidth]{Bilder/Katze1}
 
\end{document}

leaflet-01