BEFORE YOU BEGIN... You first need the data you wish to plot in a form acceptable for tikz. I find that table data with headers is easiest (file type .dat). This can be easily generated using MATLAB. Some tips:
Next, you're going to want to add a few things to the preamble of your file. Now, let's look at a fairly simple example. The tex code is on the left, and the resulting plot is on the right. ![]() \pgfplotstableread{tikz/Data_CIT_0D.dat}{\zero} \pgfplotstableread{tikz/Data_CIT_2D.dat}{\two} \pgfplotstableread{tikz/Data_CIT_3D.dat}{\three} \begin{tikzpicture} \begin{axis}[ xmin=0, xmax=30, xlabel={\LARGE $(t-t^\star)/\tau_p$}, ylabel={\LARGE$ \widetilde{T}_g $}, yticklabel style = {font=\LARGE}, xticklabel style = {font=\LARGE}, ] \addplot[name path = A, black, solid, line width = 2pt] table [x={t}, y = {T_mean}] {\two}; \label{2D} \addplot[name path = B, blue, opacity = 0.25, line width = 0pt] table [x={t}, y = {T_up}] {\two}; \addplot[name path = C, blue, opacity = 0.25, line width = 0pt] table [x={t}, y = {T_down}] {\two}; \addplot[blue, opacity =0.25] fill between[of=B and C]; \addplot[name path = A, black, solid, line width = 2pt] table [x={t}, y = {T_mean}] {\three}; \addplot[name path = B, violet, opacity =.50, solid, line width = 0pt] table [x={t}, y = {T_up}] {\three}; \addplot[name path = C, violet, opacity = 0.50, solid, line width = 0pt] table [x={t}, y = {T_down}] {\three}; \addplot[violet, opacity = 0.5] fill between[of=B and C]; \addplot[black, solid, line width = 2pt] table [x={t}, y = {T_mean}] {\zero}; \end{axis} \end{tikzpicture} EXTERNALIZING TIKZ.... If you plan to generate a large number of figures using tikz (especially if these files contain a lot of data), you’ll want to externalize tikz so that your main LaTeX file doesn’t have to recompile all of the figures every time you compile the main document (this can take a long time and LaTeX can also run out of the memory required to do it at all, even if you don’t mind the wait). Fortunately, this is pretty easy!
EASY REFERENCE OF SYMBOLS IN CAPTIONS Tikz makes it seamless to integrate a legend or refer to symbols/lines in the figure within a caption. All that is required to do this is to label each of your plots using \label{<name this plot>} and can then use the command \ref{<name the plot>} in the caption or elsewhere in the text. If you have externalized your tikz figures, you'll need to handle caption legends a bit differently. In the preamble to your main document you will need to define a tikz picture for your legend. An example of this is for a blue, dashed line is: \newcommand{\ModelTp}{\raisebox{6pt}{\tikz{\draw[blue,dashed,line width=3pt](0,0) -- (16mm,0);}}} Then, you'll need to reference it in the caption as:
\protect \ModelTp Here, the '\protect' is needed to allow a tikz picture to show up in the caption text.
0 Comments
Learning LaTeX can be a daunting task, especially when you're teaching yourself and stuck consulting stack exchange for hours on end. To spare others some of those early growing pains, I've created a quick start guide, as well as a template. The template includes the main pieces that I have used time and time again in drafting papers and reports.
3. Figures: You will undoubtedly need to add images/plots/figures to your document and this is pretty straight forward. Similarly to the table example, you first generate the figure environment (\begin{figure} \end{figure}) which will label your figure and give it a caption (if you choose). Inside of this environment, you include an image using \includegraphics[<specify scale, height or width of the image here>]{<specify the path to the file relative to the location of your .tex file>} 4. Equations: For me, writing equations is the biggest selling point for LaTeX. Once you get used to coding up equations, this method is so much quicker than any other equation editor and looks orders of magnitude nicer too. The two main equation environments that I use are the 'equation' environment (\begin{equation} \end{equation}) and the align environment (\begin{align} \end{align}). The main difference between these two is that the align environment allows you to (as the name suggests) align lines of equations, using the '&' key. This is handy for making your equations look cleaner and more organized, or to display an equation that is too long for a single line. Both these environments will by default number your equations. If you do not want a number, you can either include \nonumber at the end of the equation, or, you can use the equation* or align* environments. You can also enter into 'math' mode inline in your document using $ <put your equation code here> $. Using $$ $$ will cause a line break and display like \begin{equation*} \end{equation*}. To serve as a launching off point, here is a template with all the main building blocks that I tend to use regularly. I hope you find it to be helpful! ![]()
When starting out with LaTeX, you'll undoubtedly ask yourself, 'But isn't [insert text editor you usually use] so much quicker/easier/etc.?' Maybe it is right now, but with practice, typesetting with LaTeX is quicker and looks more polished (especially when creating documents with lots of equations). In fact, once you get the hang of coding in LaTeX, you'll realize how time-consuming the equation editor in ppt and word really was and how much more streamlined having control over all aspects of the typesetting is. |