no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | latex:tikz:scalebar [2020/06/10 21:43] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~ODT~~ | ||
+ | ====== fancy way to generate scale bars with Tikz ====== | ||
+ | The way to display scale bars shown [[: | ||
+ | You'll need: {{ : | ||
+ | * an image you know the scale of and want to draw the scale bar on, e.g. the image shown on the right((it' | ||
+ | * MATLAB with this m-file: {{: | ||
+ | * this minimal tex-file: {{: | ||
+ | Both files are explained in a bit more detail at the end of this page, for now I'll just walk you through: | ||
+ | |||
+ | ===== WorkFlow ===== | ||
+ | - Start MATLAB, load scalebar.m and start it. | ||
+ | - The script prompts you to load an image, choose " | ||
+ | - The script prompts you to define the length of the scale bar you're gonna draw in the next step, choose the default "21 cm" for now | ||
+ | - The script displays the image of my head and asks you to define a start-point of the scale-bar, choose the tip of the nose | ||
+ | - After that, choose the back of my head for the end of the scale-bar | ||
+ | - Note the " | ||
+ | - copy the output in the command-line-section of MATLAB | ||
+ | - paste this output into your .tex-file | ||
+ | - if the .tex file and the image are in the same folder, just proceed, if not, change the path to the image! | ||
+ | - compile the file | ||
+ | - Figure 1 of the document should show | ||
+ | * the exact same scale-bar you've drawn in MATLAB overlayed over the image. | ||
+ | * a second scale bar which shows a reasonable length (5cm in our case){{ | ||
+ | - change \def\x{100} and \def\y{100} on lines 24 and 25 of the copied text to position the scale bar where you'd like to have it and uncomment line 29 to turn off the original scale bar. | ||
+ | - enjoy typographically correct scale bars in the resulting {{: | ||
+ | | ||
+ | |||
+ | |||
+ | ===== LaTeX-File ===== | ||
+ | The preamble is nothing too fancy | ||
+ | <code latex> | ||
+ | \documentclass{article} | ||
+ | \usepackage{tikz} | ||
+ | \usepackage[ansinew]{inputenc} | ||
+ | \usepackage{siunitx} | ||
+ | \usepackage{hyperref} | ||
+ | </ | ||
+ | |||
+ | The block below is used to start the document and to set up the image | ||
+ | <code latex> | ||
+ | \begin{document} | ||
+ | \author{David Haberthür} | ||
+ | \title{David Haberthür' | ||
+ | \date{\today} | ||
+ | \maketitle | ||
+ | \begin{figure}[h] | ||
+ | \centering | ||
+ | </ | ||
+ | |||
+ | Inside here you'll copy the result from the MATLAB-skript, | ||
+ | <code latex> | ||
+ | \caption{Three dimensional visualization of David Haberthürs Head, released under a \href{http:// | ||
+ | \label{fig: | ||
+ | \end{figure} | ||
+ | \end{document} | ||
+ | </ | ||
+ | |||
+ | ===== MATLAB-File ===== | ||
+ | |||
+ | The block below asks the user to select an image-file that is then subsequently used for calculations | ||
+ | <code matlab> | ||
+ | [ filename, pathname] = ... | ||
+ | | ||
+ | ' | ||
+ | |||
+ | image=imread([pathname filesep filename]); | ||
+ | </ | ||
+ | |||
+ | The scale bar is defined by asking the user to click on the image for a start- and end-point. | ||
+ | <code matlab> | ||
+ | h = helpdlg(' | ||
+ | uiwait(h); | ||
+ | [ x1,y1 ] = ginput(1); | ||
+ | </ | ||
+ | the rest is just simple, but boring calculations and semi-nice output, which takes care of setting up the necessary lengths for TikZ. | ||
+ | |||
+ | ===== References ===== | ||
+ | TikZ: http:// | ||
+ | MATLAB: http:// |