trying to add subcaption or subfloat with circuitikz or tabular but could not succeed - tabular

I've been trying to add subcaption under the circuit drawing but could not succeed yet. I do not know how to add \subcaption or \subfloat. I only know how to do that with images but not with \circuitikz or \tabular
\documentclass[10pt,letterpaper,twocolumn,aps,pra, superscriptaddress,longbibliography]{revtex4-2}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{braket}
\usepackage{circuitikz}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\usepackage[export]{adjustbox}
\usepackage{subcaption,graphicx}
\captionsetup{
subrefformat=parens
}
\begin{document}
\begin{figure}[h]
\centering
\begin{circuitikz}[american,baseline=(current bounding box.center) ]
\draw
(0,1) to [short, -*](0,1)
to [inductor](0,-1)
to [short, -*](0,-1);
\end{circuitikz}
\subcaptionbox{}[.4\linewidth][c]
\hfil
\subcaptionbox{}[.4\linewidth][c]{
\includegraphics[width=\linewidth]{Array-Falsecolour}}
\caption{The kinetic inductor a) A circuit diagram of an inductor. b) A fabricated JJ array with Manhattan-style.}
\label{array}
\end{figure}
\end{document}
My expectation is to have the subcaption 'a' under the inductor element, not in the middle of the whole figure.

You can use the circuitikz the same way you use \includegraphics inside the \subcaptionbox:
\documentclass[10pt,letterpaper,twocolumn,aps,pra, superscriptaddress,longbibliography]{revtex4-2}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{braket}
\usepackage{circuitikz}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\usepackage[export]{adjustbox}
\usepackage{subcaption,graphicx}
\captionsetup{
subrefformat=parens
}
\begin{document}
\begin{figure}[h]
\centering
\subcaptionbox{}[.4\linewidth][c]{%
\begin{circuitikz}[american,baseline=(current bounding box.center) ]
\draw
(0,1) to [short, -*](0,1)
to [inductor](0,-1)
to [short, -*](0,-1);
\end{circuitikz}%
}
\hfil
\subcaptionbox{}[.4\linewidth][c]{%
\includegraphics[width=\linewidth]{example-image-duck}%
}
\caption{The kinetic inductor a) A circuit diagram of an inductor. b) A fabricated JJ array with Manhattan-style.}
\label{array}
\end{figure}
\end{document}

Related

How to center this piece of text in ShareLateX (editor) or Latex (in general)?

I am writing a resume and want to center text at the top of the document which contains my name and email details, like this
I used \begin{center} and \end{center} but it doesnt seem to work
Here is my code:
\begin{document}
\begin{tabular*}{\linewidth}{l#{\extracolsep{\fill}}r}
\vspace{-4mm}
\textbf{\LARGE Samuel Adams}
\\
& \\ \textbf{Notsville, TX} $|$
\textbf{\phone \ \ +1 (000) 000 0000} $|$
\textbf{cxcx#gmail.com} $|$ \textbf{{www.linkedin.com/ffdfs}}\\
\end{tabular*}
\vspace{1 mm}
Can anyone help me center this piece of text?
This is how it looks right now. I am looking to center both lines just like we do it in word.
The table will be in the middle of the page once
you make the left and right margin the same size
use \noindent in front of the table to avoid it being indented as the first line of a new paragraph
(I'm actually not sure why you use a table for this, you never use the second column...)
\documentclass[a4paper,10pt]{article}
\usepackage[empty]{fullpage}
\usepackage{xcolor}
\usepackage{url}
\usepackage{wasysym}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,bindingoffset=0.3in, left=0.5in,right=0.5in,top =0.8in,bottom=-5in, footskip=.25in]{geometry}
\begin{document}
\noindent\begin{tabular*}{\linewidth}{l#{\extracolsep{\fill}}r}
\textbf{\LARGE Samuel Adams} & \\
\textbf{Notsville, TX} $|$ \textbf{\phone \ \ +1 (000) 000 0000} $|$
\textbf{cxcx#gmail.com} $|$ \textbf{{www.linkedin.com/ffdfs}} & \\
\hline
\end{tabular*}
\vspace{1 mm}
\end{document}

Embedding content of SVG file in latex document

I'm computing a plot and have the data in 'SVG' format as string in memory. I'd like to use that SVG string in a latex document, which is also being produced by computation.
I could save the file to my disk and then use the file in my latex document. However I'd prefer to simply put the string with the content of the SVG data directly in my latex document. How can I do that?
If your svg plot is not too complicate, you could use the svg path operation of tikz:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{svg.path}
\begin{document}
\begin{tikzpicture}
\draw svg {M 0 0 L 20 20 h 10 a 10 10 0 0 0 -20 0};
\end{tikzpicture}
\end{document}

How to scale a barplot in tikz without scaling the text?

I have a barplot in latex in tikz, that I want to scale (reduce width, increase length), but without the text having the same effect.
\begin{figure}
\centering
\resizebox{0.8\textwidth}{1.3\textwidth}{
\begin{tikzpicture}
\pgfplotsset{every tick label/.append style={font=\tiny}}
\begin{axis}[ xmajorgrids=true,
xbar, xmin=0,
xlabel={Gini Coefficient, OECD Countries \%},
symbolic y coords={{Australia},{Austria},{Belgium},{Canada},{Chile},{Costa Rica},{Czech Republic},{Denmark},{Estonia},{Finland},{France},{Germany},{Greece},{Hungary},{Iceland},{Ireland},{Israel},{Italy},{Japan},{Korea},{Latvia},{Lithuania},{Luxembourg},{Mexico},{Netherlands},{New Zealand},{Norway},{Poland},{Portugal},{Slovak Republic},{Slovenia},{South Africa},{Spain},{Sweden},{Switzerland},{Turkey},{United Kingdom},{United States}},
ytick=data,
nodes near coords, nodes near coords align={horizontal},
ytick=data,
]
\addplot[fill=blue!90,draw=black!70,tickwidth = 0pt,bar width=4pt,label style={font=\small}, tick label style={font=\small}] coordinates {(0.33,{Australia}) (0.284,{Austria}) (0.266,{Belgium}) (0.307,{Canada}) (0.454,{Chile}) (0.48,{Costa Rica}) (0.253,{Czech Republic}) (0.263,{Denmark}) (0.314,{Estonia}) (0.266,{Finland}) (0.291,{France}) (0.294,{Germany}) (0.333,{Greece}) (0.288,{Hungary}) (0.255,{Iceland}) (0.297,{Ireland}) (0.344,{Israel}) (0.328,{Italy}) (0.339,{Japan}) (0.355,{Korea}) (0.346,{Latvia}) (0.378,{Lithuania}) (0.304,{Luxembourg}) (0.458,{Mexico}) (0.285,{Netherlands}) (0.349,{New Zealand}) (0.262,{Norway}) (0.284,{Poland}) (0.331,{Portugal}) (0.241,{Slovak Republic}) (0.244,{Slovenia}) (0.62,{South Africa}) (0.341,{Spain}) (0.282,{Sweden}) (0.296,{Switzerland}) (0.404,{Turkey}) (0.351,{United Kingdom}) (0.391,{United States})};
\end{axis}
\end{tikzpicture}
}
\caption{\small{Gini coefficient, OECD countries, 2017 or latest available, source: \url{https://data.oecd.org/inequality/income-inequality.htm}}}
\label{fig:giniOECD}
\end{figure}
I would like the bar charts a bit further apart to each other, the blank areas on top and at the end to be removed, the markers (text within the chart that show the values) to be smaller and all the text to be at normal scale, not skewed like that.
Never ever use \resizebox (or \scalebox) for things that contain text.
to set the height and the width of a pgfplot, the height and width keywords can be used
don't put formatting instructions in arguments of macros like \caption. If you want the caption in another font size, you can adjust it with the help of the caption package
\documentclass{article}
\usepackage{pgfplots}
\usepackage{hyperref}
\usepackage[font=small]{caption}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\pgfplotsset{%
width=.8\textwidth,
height=1.5\textwidth
}
\begin{axis}[
xmajorgrids=true,
xbar,
xmin=0,
xlabel={Gini Coefficient, OECD Countries \%},
symbolic y coords={{Australia}, {Austria}, {Belgium}, {Canada}, {Chile}, {Costa Rica}, {Czech Republic}, {Denmark}, {Estonia}, {Finland}, {France}, {Germany}, {Greece}, {Hungary}, {Iceland}, {Ireland}, {Israel}, {Italy}, {Japan}, {Korea}, {Latvia}, {Lithuania}, {Luxembourg}, {Mexico}, {Netherlands}, {New Zealand}, {Norway}, {Poland}, {Portugal}, {Slovak Republic}, {Slovenia}, {South Africa}, {Spain}, {Sweden}, {Switzerland}, {Turkey}, {United Kingdom}, {United States}},
ytick=data,
nodes near coords,
nodes near coords align={horizontal},
enlarge y limits=0.02,
]
\addplot[fill=blue!90,draw=black!70,tickwidth = 0pt,bar width=4pt,label style={font=\small}, tick label style={font=\small}] coordinates {(0.33,{Australia}) (0.284,{Austria}) (0.266,{Belgium}) (0.307,{Canada}) (0.454,{Chile}) (0.48,{Costa Rica}) (0.253,{Czech Republic}) (0.263,{Denmark}) (0.314,{Estonia}) (0.266,{Finland}) (0.291,{France}) (0.294,{Germany}) (0.333,{Greece}) (0.288,{Hungary}) (0.255,{Iceland}) (0.297,{Ireland}) (0.344,{Israel}) (0.328,{Italy}) (0.339,{Japan}) (0.355,{Korea}) (0.346,{Latvia}) (0.378,{Lithuania}) (0.304,{Luxembourg}) (0.458,{Mexico}) (0.285,{Netherlands}) (0.349,{New Zealand}) (0.262,{Norway}) (0.284,{Poland}) (0.331,{Portugal}) (0.241,{Slovak Republic}) (0.244,{Slovenia}) (0.62,{South Africa}) (0.341,{Spain}) (0.282,{Sweden}) (0.296,{Switzerland}) (0.404,{Turkey}) (0.351,{United Kingdom}) (0.391,{United States})};
\end{axis}
\end{tikzpicture}
\caption{Gini coefficient, OECD countries, 2017 or latest available, source: \url{https://data.oecd.org/inequality/income-inequality.htm}}
\label{fig:giniOECD}
\end{figure}
\end{document}

d3.js stacked barchart not drawing along x axis?

I'm stumped on this one, I need another set of eyes to help me see what I'm missing. I have a bl.ock up here:
http://bl.ocks.org/hepplerj/c419baa3abf7363cd2d5
As you'll see, a few of the rect elements aren't drawing along the x axis correctly. Any pointers on what I'm overlooking? Much appreciated!
There's just a minor issue with your code. First of all, here's a fiddle that's the same as your bl.ock: http://jsfiddle.net/gp2ex7fw/
View source and count the <g class="bar"> elements, and you'll see that there are only seven, whereas you have data for eight grains. millet/sorghum groats is missing altogether. This creates gaps in each bar, resulting in the bar not filling up the entire height.
This is because of the following part of your code:
d3.select("svg").selectAll("g")
.data(stackLayout(stackData))
.enter()
.append("g")
.attr("class", "bar")
When you do selectAll("g"), you're also selecting the first g element (used for transformation) that was attached to your svg element earlier.
The fix is very easy. Just change the above code to:
d3.select("svg").selectAll(".bar")
.data(stackLayout(stackData))
.enter()
.append("g")
.attr("class", "bar")
Now we're only selecting g elements with class="bar" and not missing any data. Here's a working fiddle: http://jsfiddle.net/gp2ex7fw/1/

Gradient text fill using GD - PHP

I need a function that renders gradient on a text using GD
something like
function gradientText($text,$font,$color1,$color2)
{
..
}
I suggest you try to build that function based your own needs.
You will want to center the text vertically/horizontal, change font size, etc...
Start on this function by Christopher Kramer, code is also below this answer...
http://www.php.net/manual/en/function.imagefill.php#93920
then you can use imagettfbbox if you want to use custom font files.
http://www.php.net/manual/en/function.imagettfbbox.php
Here is a sample image I generated using those 2 functions.
Pasting Chris' code of gradient here for reference:
<?php
function gradient($w=100, $h=100, $c=array('#FFFFFF','#FF0000','#00FF00','#0000FF'), $hex=true) {
/*
Generates a gradient image
Author: Christopher Kramer
Parameters:
w: width in px
h: height in px
c: color-array with 4 elements:
$c[0]: top left color
$c[1]: top right color
$c[2]: bottom left color
$c[3]: bottom right color
if $hex is true (default), colors are hex-strings like '#FFFFFF' (NOT '#FFF')
if $hex is false, a color is an array of 3 elements which are the rgb-values, e.g.:
$c[0]=array(0,255,255);
*/
$im=imagecreatetruecolor($w,$h);
if($hex) { // convert hex-values to rgb
for($i=0;$i<=3;$i++) {
$c[$i]=hex2rgb($c[$i]);
}
}
$rgb=$c[0]; // start with top left color
for($x=0;$x<=$w;$x++) { // loop columns
for($y=0;$y<=$h;$y++) { // loop rows
// set pixel color
$col=imagecolorallocate($im,$rgb[0],$rgb[1],$rgb[2]);
imagesetpixel($im,$x-1,$y-1,$col);
// calculate new color
for($i=0;$i<=2;$i++) {
$rgb[$i]=
$c[0][$i]*(($w-$x)*($h-$y)/($w*$h)) +
$c[1][$i]*($x *($h-$y)/($w*$h)) +
$c[2][$i]*(($w-$x)*$y /($w*$h)) +
$c[3][$i]*($x *$y /($w*$h));
}
}
}
return $im;
}
function hex2rgb($hex)
{
$rgb[0]=hexdec(substr($hex,1,2));
$rgb[1]=hexdec(substr($hex,3,2));
$rgb[2]=hexdec(substr($hex,5,2));
return($rgb);
}
// usage example
$image=gradient(300, 300, array('#000000', '#FFFFFF', '#FF0000', '#0000FF'));
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
Using GD
http://planetozh.com/blog/my-projects/images-php-gd-gradient-fill/ offers a class to create a gradient with GD.
Gradient can be linear (horizontal or vertical), radial, rectangle, diamond. That's the same options you would find on Adobe Photoshop.
The class methods fill rectangular areas with a gradient, so you could achieve a rather great gradient effect with the following method:
create a gradient rectangle with this class
write your text in the specified font
mix them:
you could cut the gradient picture with the shape of the text picture
you could apply the gradient picture as a pattern for the text picture
Using ImageMagick
Instead to use GD, I would use ImageMagick.
See http://www.imagemagick.org/Usage/fonts/#gradient for a sample of how to use ImageMagick to achieve that, and http://www.imagemagick.org/Usage/canvas/#gradient for all the gradients options.

Resources