# Designing a curved grating, i.e. a specific dashed arc?

I am trying to recreate this diagramm on tikz:

Until now I have managed this:

with this code:

\begin{figure}
\centering
\begin{tikzpicture}
\def\R{2}
% Rowland Circle
\draw (0,0) circle (\R);
% Grating
\draw[line width=0.5mm, dash pattern=on 6pt off 6pt] (-2*\R,+\R) arc[start angle=-180, end angle=0, radius=2*\R];
% Geometric Parameters
% Calculate the coordinates of P
\pgfmathsetmacro\x{\R * cos(60)}
\pgfmathsetmacro\y{\R * sin(60)}
\path
coordinate (C) at (0,0)
coordinate (O) at (0,\R)
coordinate (P) at (\x,\y)
coordinate (A) at (0,-\R);
\fill (C) circle (1.5pt) node [left] {$C$};
\fill (O) circle (1.5pt) node [above] {$O$};
\fill (P) circle (1.5pt) node [above] {$P$};
\draw (0,-\R) -- (O)
(C) -- (P)
-- (0,-\R)
(O) -- (-2*\R,\R) node [midway, below] {$2R$};
\path (C) -- (O) node [midway, left] {$R$};
\pic[draw, angle radius=1cm, angle eccentricity=1.5] {angle=P--C--O};
\pic[draw, angle radius=1cm, angle eccentricity=1.5] {angle=P--A--O};
\end{tikzpicture}
\caption{Caption}
\label{fig:RowlandCircle}
\end{figure}


As you can see, I have not got the curved grating right. The centre of the grating needs to be a dash on at coordinate (A)=(0,-\R), like in the first image. I also don't know how I can illustrate the grating constant d. I would like for the grating to be thick at the bottom and then thin for the rest of the semi circle, like this:

Lastly, when I try annotate the angles at the \pic command with for example:

\pic[draw, angle radius=1cm, angle eccentricity=1.5, "$\alpha$"] {angle=P--C--O};


I get errors such as:

Missing \endcsname inserted. Missing \endcsname inserted. Package xcolor Error: Undefined color "$\alpha$"'. Package xcolor Error: Undefined color "$\alpha$"'. Package xcolor Error: Undefined color "$\alpha$"'. Runaway argument?

These are the relevant libraries that I am using:

\usepackage{tikz-3dplot} %for plots
\usetikzlibrary{3d}
\usetikzlibrary{patterns.meta}
\usepgfplotslibrary{colorbrewer,external}
% \tikzexternalize
\usepgflibrary{arrows.meta,decorations.markings}
\usetikzlibrary{calc,patterns,angles,quotes,intersections,shapes.geometric,positioning}


I know for "$\alpha$" to work one needs the quotes library which I do have. Could it be that another one of the libraries is hindering the quotes command?

Thanks in advance for any kind of help!

EDIT: Thank you for the help so far. That curved grating is beautiful. The full settings code is here:

\PassOptionsToPackage{table,svgnames,dvipsnames}{xcolor}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage[ngerman,english]{babel} % english is the same as american or USenglish
\usepackage[autostyle]{csquotes}
\usepackage[%
backend=biber,
url=true,
style=numeric, % alphabetic, numeric
sorting=none, % default == nty, https://tex.stackexchange.com/questions/51434/biblatex-citation-order
maxnames=4,
minnames=3,
maxbibnames=99,
giveninits,
uniquename=init]{biblatex} % TODO: adapt citation style
\usepackage{graphicx}
\usepackage{scrhack} % necessary for listings package
\usepackage{listings}
\usepackage{lstautogobble}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{booktabs} % for better looking table creations, but bad with vertical lines by design (package creator despises vertical lines)
\usepackage[final]{microtype}
\usepackage{caption}
\usepackage{ifthen} % for comparison of the current language and changing of the thesis layout
\usepackage{pdftexcmds} % string compare to work with all engines
\usepackage{paralist} % for condensed enumerations or lists
% \usepackage{subfig} % for having figures side by side
\usepackage{siunitx} % for physical accurate units and other numerical presentations
\usepackage{multirow} % makes it possible to have bigger cells over multiple rows in a table
\usepackage{array} % different options for table cell orientation
\usepackage{makecell} % allows nice manual configuration of cells with linebreaks in \thead and \makecell with alignments
\usepackage{pdfpages} % for including multiple pages of pdfs
\usepackage{adjustbox} % can center content wider than the \textwidth
\usepackage{tablefootnote} % for footnotes in tables as \tablefootnote
\usepackage{threeparttable} % another way to add footnotes as \tablenotes with \item [x] <your footnote> after setting \tnote{x}

% https://tex.stackexchange.com/questions/42619/x-mark-to-match-checkmark
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{amsmath}
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%

\usepackage{tikz-3dplot} %for plots
\usetikzlibrary{3d}
\usetikzlibrary{patterns.meta}
\usepgfplotslibrary{colorbrewer,external}
% \tikzexternalize
\usepgflibrary{arrows.meta,decorations.markings}
\usetikzlibrary{calc,patterns,angles,quotes,intersections,shapes.geometric,positioning}

\usepackage[capitalize]{cleveref}
\crefformat{equation}{(#2#1#3)}
\usepackage{subcaption} % For subfigures

\usepackage{bm}
\usepackage{physics}
\AtBeginDocument{\RenewCommandCopy\qty\SI} % as physics and siunitx packages both have a \qty command
\usepackage{amsfonts}
\usepackage[version=4]{mhchem}
\usepackage{trfsigns} % transformation signs for Fourier and Laplace
\usepackage{circuitikz} % for circuits
\usepackage{yhmath} % for \wideparen command; if causes issues: https://tex.stackexchange.com/questions/15468/frown-and-mathop-stackrel-overset

%%%%%

\usepackage[acronym]{glossaries} % TODO: include "acronym" if glossary and acronym should be separated

% \loadglsentries{pages/glossary.tex} % important update for glossaries, before document
\input{pages/glossary}
\makeglossaries

\bibliography{bibliography}

\setkomafont{disposition}{\normalfont\bfseries} % use serif font for headings

% Define TUM corporate design colors
% Taken from http://portal.mytum.de/corporatedesign/index_print/vorlagen/index_farben
\definecolor{TUMBlue}{HTML}{0065BD}
\definecolor{TUMSecondaryBlue}{HTML}{005293}
\definecolor{TUMSecondaryBlue2}{HTML}{003359}
\definecolor{TUMBlack}{HTML}{000000}
\definecolor{TUMWhite}{HTML}{FFFFFF}
\definecolor{TUMDarkGray}{HTML}{333333}
\definecolor{TUMGray}{HTML}{808080}
\definecolor{TUMLightGray}{HTML}{CCCCC6}
\definecolor{TUMAccentOrange}{HTML}{E37222}
\definecolor{TUMAccentLightBlue}{HTML}{98C6EA}
\definecolor{TUMAccentBlue}{HTML}{64A0C8}

\definecolor{electriccyan}{rgb}{0.0, 1.0, 1.0}
\definecolor{ao(english)}{rgb}{0.0, 0.5, 0.0}
\definecolor{mediumgrey}{rgb}{0.57, 0.64, 0.69} % medium grey (cadetgrey)
\definecolor{royalpurple}{rgb}{0.47, 0.32, 0.66}
\definecolor{photoresist}{RGB}{255,99,71}
\definecolor{substrate}{RGB}{176,196,222}
\definecolor{yig}{rgb}{1.0, 0.75, 0.0} % Amber
\definecolor{silver}{rgb}{0.79, 0.75, 0.73} % Pale Silver

\pgfdeclarepattern{
name=hatch,
parameters={\hatchsize,\hatchangle,\hatchlinewidth},
bottom left={\pgfpoint{-.1pt}{-.1pt}},
top right={\pgfpoint{\hatchsize+.1pt}{\hatchsize+.1pt}},
tile size={\pgfpoint{\hatchsize}{\hatchsize}},
tile transformation={\pgftransformrotate{\hatchangle}},
code={
\pgfsetlinewidth{\hatchlinewidth}
\pgfpathmoveto{\pgfpoint{-.1pt}{-.1pt}}
\pgfpathlineto{\pgfpoint{\hatchsize+.1pt}{\hatchsize+.1pt}}
\pgfpathmoveto{\pgfpoint{-.1pt}{\hatchsize+.1pt}}
\pgfpathlineto{\pgfpoint{\hatchsize+.1pt}{-.1pt}}
\pgfusepath{stroke}
}
}

\tikzset{
hatch size/.store in=\hatchsize,
hatch angle/.store in=\hatchangle,
hatch line width/.store in=\hatchlinewidth,
hatch size=5pt,
hatch angle=0pt,
hatch line width=.5pt,
}

% Settings for pgfplots
\pgfplotsset{
% For available color names, see http://www.latextemplates.com/svgnames-colors
cycle list={TUMBlue\\TUMAccentOrange\\TUMAccentGreen\\TUMSecondaryBlue2\\TUMDarkGray\\},
}

% Settings for lstlistings

% Use this for basic highlighting
\lstset{%
basicstyle=\ttfamily,
columns=fullflexible,
autogobble,
keywordstyle=\bfseries\color{TUMBlue},
stringstyle=\color{TUMAccentGreen}
}

% use this for C# highlighting
% %\setmonofont{Consolas} %to be used with XeLaTeX or LuaLaTeX
% \definecolor{bluekeywords}{rgb}{0,0,1}
% \definecolor{redstrings}{rgb}{0.64,0.08,0.08}
% \definecolor{types}{rgb}{0.17,0.57,0.68}

% \lstset{language=[Sharp]C,
% captionpos=b,
% %numbers=left, % numbering
% %numberstyle=\tiny, % small row numbers
% frame=lines, % above and underneath of listings is a line
% showspaces=false,
% showtabs=false,
% breaklines=true,
% showstringspaces=false,
% breakatwhitespace=true,
% escapeinside={(*@}{@*)},
% morekeywords={partial, var, value, get, set},
% keywordstyle=\color{bluekeywords},
% stringstyle=\color{redstrings},
% basicstyle=\ttfamily\small,
% }

% Settings for search order of pictures
\graphicspath{
{logos/}
{figures/}
}

% Set up hyphenation rules for the language package when mistakes happen
\babelhyphenation[english]{
an-oth-er
ex-am-ple
}

% Decide between
%\newcommand{\todo}[1]{\textbf{\textsc{\textcolor{TUMAccentOrange}{(TODO: #1)}}}} % for one paragraph, otherwise error!
%\newcommand{\done}[1]{\textit{\textsc{\textcolor{TUMAccentBlue}{(Done: #1)}}}} % for one paragraph, otherwise error!
% and
\newcommand{\todo}[1]{{\bfseries{\scshape{\color{TUMAccentOrange}[(TODO: #1)]}}}} % for multiple paragraphs
\newcommand{\done}[1]{{\itshape{\scshape{\color{TUMAccentBlue}[(Done: #1)]}}}} % for multiple paragraphs
% for error handling of intended behavior in your latex documents.

\newcommand{\tabitem}{~~\llap{\textbullet}~~}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}} % for horizontal alignment with limited column width
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}} % for horizontal and vertical alignment with limited column width
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}} % for vertical alignment left with limited column width
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}} % for vertical alignment right with limited column width


This is the main:

\RequirePackage[l2tabu,orthodox]{nag}

% TODO: decide if one-sided/two-sided
%\documentclass[headsepline,footsepline,footinclude=false,fontsize=11pt,paper=a4,listof=totoc,bibliography=totoc,BCOR=12mm,DIV=12]{scrbook} % two-sided % original source stated: BCOR=12mm,DIV=12

% TODO: change citation style in settings
\input{settings}

% TODO: change thesis information
\newcommand*{\getUniversity}{-}
\newcommand*{\getFaculty}{-}
\newcommand*{\getTitle}{-}
\newcommand*{\getTitleGer}{Titel der Abschlussarbeit}
\newcommand*{\getAuthor}{-}
\newcommand*{\getDoctype}{-}
\newcommand*{\getSupervisor}{-}
\newcommand*{\getSubmissionDate}{-}
\newcommand*{\getSubmissionLocation}{-}

\begin{document}

% TODO: decide on used language
%\selectlanguage{ngerman}
\selectlanguage{english}

% Set page numbering to avoid "destination with the same identifier has been already used" warning for cover page.
\pagenumbering{alph}
\input{pages/cover}

\frontmatter{}

\input{pages/title}
\input{pages/disclaimer}
\input{pages/acknowledgements} % TODO: if you don't have anyone to thank for or don't wish to publish it, comment this line out.
\input{pages/abstract}
\microtypesetup{protrusion=false}
\tableofcontents{}
\microtypesetup{protrusion=true}

\mainmatter{}

\input{chapters/00_template}
\input{chapters/01_introduction.tex}
\input{chapters/02_theoretical_background.tex}
\input{chapters/03_fabrication_process.tex}
\input{chapters/04_measurement_results.tex}
\input{chapters/05_conclusions.tex}

\appendix{}

% TODO: appendix chapter
\input{pages/appendix}

\microtypesetup{protrusion=false}
\listoffigures{}
\listoftables{}
\microtypesetup{protrusion=true}
% trying to print glossary
\printglossary[type=\acronymtype,nonumberlist]
\printglossary
%
\printbibliography{}

\end{document}



I have the relevant figure in chapters/02_theoretical_background.tex. I have previously tried to use tikzexternalise which did not work. Maybe you are able to figure that out as well.

• Please complete your code so we can compile to reproduce the error.
– cfr
Commented Jul 17 at 14:49
• When I complete your code so I can (try to) compile it, the "$\alpha$" works as expected, so the problem lies in some code you're not shown. Possibly you need to load the babel library? But that's just a guess.
– cfr
Commented Jul 17 at 14:52
• Thanks for the curved grating. I have edited the main question to include the settings.tex and the main.tex. I don't know if it is possible to upload files so I just pasted the code Commented Jul 18 at 9:24
• Unfortunately, we can't compile your code to reproduce the error because we don't have many of the files you \input. And I don't think we know which document class you're using. Please see tex.meta.stackexchange.com/q/228 for help formulating a minimal example we can use to diagnose the problem. There are some issues with your settings, but I'm not sure whether they are related or not. Try adding the babel tikz library and see if that helps. (I don't know if German uses active shorthands or not.)
– cfr
Commented Jul 18 at 17:42

This suggestion extends the solution by @cfr to address the following (physical/typographical/quality of life) points:

• Grate at point A should be centered,
• Dash length of 2R arc visualizer is now calculated to fit even number of arc segments without (too much) clipping and correct spacing to grating,
• No "Magic Numbers"/hard coding, all is derived mathematically from 4 "variables" (\R, \d, \numberOfGratings, \anglePointP).

In addition, the arrow tips of the grating distance visualizer have been changed for a cleaner look; but this is more about personal preferences.

Now the only (minor) issue remaining is that the dashes of 2R arc visualizer are ending/starting to close to the grating (seems to be half a dash to close). Please note that this might not only be due to the limited mathematical precision of LaTeX, but also due to the mathematical simplification during the angle calculation.

## Code

\documentclass[tikz,border=5pt] {standalone}
\usetikzlibrary{calc,angles,quotes}

\usepackage{ifthen}

\begin {document}
\begin{tikzpicture}
% Define the radius, grating distance and number of gratings to draw
\def\R{2}
\def\d{6pt}
\def\numberOfGratings{7} % REMARK: Has to be odd!
\def\anglePointP{60}

% Rowland Circle
\draw (0,0) circle (\R);

% Grating
% Geometric Parameters
% Calculate the coordinates of P
\pgfmathsetmacro\x{\R * cos(\anglePointP)}
\pgfmathsetmacro\y{\R * sin(\anglePointP)}
\path
coordinate (C) at (0,0)
coordinate (O) at (0,\R)
coordinate (P) at (\x,\y)
coordinate (A) at (0,-\R)
;

% Mark and label all the points
\fill (C) circle (1.5pt) node [left] {$C$};
\fill (O) circle (1.5pt) node [above] {$O$};
\fill (P) circle (1.5pt) node [above] {$P$};

% Draw all the dimension markings and label the radii
\draw
(0,-\R) -- (O)
(C) -- (P)
-- (0,-\R)
(O) -- (-2*\R,\R) node [midway, below] {$2R$}
;
\path (C) -- (O) node [midway, left] {$R$};

% Draw the angle arc and add the labels
\pic[draw, angle radius=1cm, angle eccentricity=1.5, "$\alpha$"] {angle=P--A--O};
\pic[draw, angle radius=1cm, angle eccentricity=1.5, "$2\alpha$"] {angle=P--C--O};

\begin{scope}[shift=(O)]
\newdimen\circumferenceCircleTwoR
\newdimen\dashGrating
\newdimen\dashArcVisualizerTwoR
\pgfmathsetlength\circumferenceCircleTwoR{pi*4*\R cm}

% Calculate the grating parameters
\pgfmathsetlength\dashGrating{\d}
\pgfmathsetmacro{\tmpViewingAngleSingleSegement}{
(\dashGrating/\circumferenceCircleTwoR)*360
}
\pgfmathsetmacro{\gratingViewingAngleComplete}{
\tmpViewingAngleSingleSegement * \numberOfGratings * 2 - 1
}
\pgfmathsetmacro{\gratingStartAngle}{
180 - (90-\gratingViewingAngleComplete/2) - \tmpViewingAngleSingleSegement/3
% REMARK: \tmpViewingAngleSingleSegement/3 ensures that the dash at point A is centered as good as possible
}
\pgfmathsetmacro{\gratingEndAngle}{
\gratingStartAngle-\gratingViewingAngleComplete
}

% Calculate parameters for 2R arc visualizer
% Calculate the number of dashes on the (left) half of the 2R arc visualizer based upon the dashing distance of the grating
\pgfmathsetmacro{\arcVisualizerTwoRSegmentLength}{
\circumferenceCircleTwoR * (
(180-\gratingStartAngle - \tmpViewingAngleSingleSegement/3)
/360
)
}
\pgfmathsetmacro{\tmpDashNumber}{
int(
\arcVisualizerTwoRSegmentLength
/(\dashGrating/2)
)
}

% Make sure that the number of dashes is odd, so that the 2R arc visualizer starts/ends with a dash and not a void
\pgfmathiseven{\tmpDashNumber}
\ifthenelse{
\equal{\pgfmathresult}{1}
}{
\pgfmathsetmacro{\tmpDashNumber}{int(\tmpDashNumber + 1)}
}{}

% Calculate the dash pattern distance for the 2R arc visualizer
\pgfmathsetlength\dashArcVisualizerTwoR{
\arcVisualizerTwoRSegmentLength / \tmpDashNumber
}

% Draw 2R arc visualizer
\draw [dash pattern=on \dashArcVisualizerTwoR off \dashArcVisualizerTwoR]
(-2*\R,0pt) arc[start angle=-180, end angle=-\gratingStartAngle, radius=2*\R] (-\gratingEndAngle- \tmpViewingAngleSingleSegement/3:2*\R) arc [start angle=-\gratingEndAngle- \tmpViewingAngleSingleSegement/3, end angle=0, radius=2*\R]
;

% Draw grating
\draw [line width=.5mm,dash pattern=on \dashGrating off \dashGrating]

% Calculate the start and end coordinate of the grating distance marker
\coordinate (a) at ({-\gratingStartAngle+\tmpViewingAngleSingleSegement}:2*\R);
\coordinate (b) at ({-\gratingStartAngle+3*\tmpViewingAngleSingleSegement}:2*\R);

% Draw the vertical distance limiter lines as well as add distance arrow and label
\draw (a |- b) -- ++(0pt,10pt) coordinate (d) --++(0,2pt) (b) -- (d -| b) coordinate (c) --++(0,2pt);
\draw [shorten >=-0.0625mm, shorten <=-0.0625mm, <->, >=stealth]
(c) -- node [midway,above] {$d$} (d);
\end{scope}
\end{tikzpicture}
\end{document}

• Very nice! But I don't think the calculations are using floating point. Aren't they using fixed point?
– cfr
Commented Jul 18 at 15:01
• @cfr After reading your comment and some thinking, I am not sure (anymore) which mechanism is the technically relevant one. Consequently, I adapted my remark to be more general. Commented Jul 18 at 15:57
• As I understand it, TeX always uses fixed point unless you add something to implement floating point. There are pgf libraries you can load to change the way calculations are done, but otherwise you're just getting the standard TeX calculations which means anything which isn't an integer is calculated as a dimension etc. And, as you say, not very accurate.
– cfr
Commented Jul 18 at 16:01
• @cfr That is a very good point: I always assumed that using pgf by default changes to floating point (as long as one is not using dimensions explicitly). Your explanation might explain some problems with the dreaded dimension too large error I had in one of my personal projects... Commented Jul 18 at 16:10

Like this?

Although I've minimised the preamble below, there is no conflict between the code you showed and the quotes library. So the error is caused by code you've not shown. A wild guess would suggest loading the babel library.

\documentclass[tikz,border=5pt] {standalone}
\usetikzlibrary{calc,angles,quotes}
\begin {document}
\begin{tikzpicture}
\newdimen\tempdima
\def\R{2}
% Rowland Circle
\draw (0,0) circle (\R);
% Grating
% Geometric Parameters
% Calculate the coordinates of P
\pgfmathsetmacro\x{\R * cos(60)}
\pgfmathsetmacro\y{\R * sin(60)}
\path
coordinate (C) at (0,0)
coordinate (O) at (0,\R)
coordinate (P) at (\x,\y)
coordinate (A) at (0,-\R);
\fill (C) circle (1.5pt) node [left] {$C$};
\fill (O) circle (1.5pt) node [above] {$O$};
\fill (P) circle (1.5pt) node [above] {$P$};
\draw (0,-\R) -- (O)
(C) -- (P)
-- (0,-\R)
(O) -- (-2*\R,\R) node [midway, below] {$2R$};
\path (C) -- (O) node [midway, left] {$R$};
\pic[draw, angle radius=1cm, angle eccentricity=1.5, "$\alpha$"] {angle=P--A--O};
\pic[draw, angle radius=1cm, angle eccentricity=1.5, "$2\alpha$"] {angle=P--C--O};
\begin{scope}[shift=(O)]
\draw [dashed] (-2*\R,0pt) arc[start angle=-180, end angle=-110, radius=2*\R] (-70:2*\R) arc [start angle=-70, end angle=0, radius=2*\R];
\draw [line width=.5mm,dash pattern=on 6pt off 6pt] (-110:2*\R) arc [start angle=-110,end angle=-70,radius=2*\R];
\pgfmathsetlength\tempdima{pi*4*\R cm}
\pgfmathsetmacro\tempa{ (6pt/\tempdima)*360  }
\coordinate (a) at ({-110+\tempa}:2*\R);
\coordinate (b) at ({-110+3*\tempa}:2*\R);
\draw (a |- b) -- ++(0pt,10pt) coordinate (d) (b) -- (d -| b) coordinate (c);
\draw [shorten >=-2pt, shorten <=-2pt, >-<] (c) -- node [midway,above] {$d$} (d);
\end{scope}
\end{tikzpicture}
\end {document}
`
• Any particular reason for down-voting? Seems rather random ....
– cfr
Commented Jul 19 at 1:38